gpt4 book ai didi

PHP 脚本无法识别缺失的变量

转载 作者:行者123 更新时间:2023-11-30 01:29:27 24 4
gpt4 key购买 nike

我正在编写一个小脚本,将产品从 csv 文件上传到我的网站。我一直遇到一个问题,当 $result 存在时,我的 if($result) echo "hi"; 会回显,但如果我输入 if(!result)if(empty($result)if(!isset(result)) 当没有结果时不会回显...在我的产品列表代码列表中。我有 3 个产品代码,其中 2 个在数据库中,当我有 if($result) 时,它回显 2 'hi' 但如果我有 if(!result) 则没有任何回显,而它应该回显 1 hi。

while($data = fgetcsv($handle)) {

//Gets products to be added from txt file.
$codes = explode("\n", file_get_contents("productlist.txt"));

foreach($codes as $code) {

if($data[3] == $code) {

$name = $data[2];
$model = $data[3];
$description = strip_tags($data[6]);
echo $price = round($data[7] + 20 + (0.05 * $data[7])) - 0.05; echo "</br>";
$image = "data/W_Sexy_Lingerie_Series_Lingerie-Supplies/" . $model . ".jpg";

//Check to see if product already exists
$query = "SELECT `product_id` FROM `oc_product` WHERE `model`='$model'";
$result = $con->query($query);

if(empty($result)) echo "hi";

break;

//Insert product information
$query = "INSERT INTO `oc_product` (`model`, `quantity`, `image`, `price`, `status`) VALUES
('$model', '5', '$image', '$price', 1)";

if (!$con->query($query)) {
echo $con->error;
}

//Get product ID
$query = "SELECT `product_id` FROM `oc_product` WHERE `model`='$model'";
$result = $con->query($query);

$rows = $result->fetch_array();

$product_id = $rows[0];

//Insert product category
$query = "INSERT INTO `oc_product_to_category` (`product_id`, `category_id`) VALUES ('$product_id', 59)";

if (!$con->query($query)) {
echo $con->error;
}

//Insert product description
$query = "INSERT INTO `oc_product_description` (`product_id`, `language_id`, `name`, `description`,"; $query .= " `meta_description`, `meta_keyword`)";
$query .= " VALUES ('$product_id', 1, '$name', '$description', '$description', '$description')";

if (!$con->query($query)) {
echo $con->error;
}

}

}

}

}

newProducts($handle,$con);

最佳答案

if( $result->num_rows == 0 ) echo "hi";

关于PHP 脚本无法识别缺失的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17637117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com