gpt4 book ai didi

php - MySQL 中的 INSERT 第二次不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:27 25 4
gpt4 key购买 nike

我的 MySQL 请求有问题。插入不会在一夜之间起作用。我不知道为什么。这是他第二次这样做。

我收到以下 mysqli_error:

Erreur :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 ,'ljhb', '5456', '0-aVeeRYLr-fruits-et-legumes-bio-' at line 1

 $connect = mysqli_connect("localhost","root","","db");
$name = mysqli_query($connect,"SELECT name FROM fruitandvegetable WHERE name='".mysqli_real_escape_string($connect,stripcslashes($_POST['name']))."'")
or die('Erreur :'.mysqli_error());
$nombre = mysqli_query($connect,"SELECT nombre FROM fruitandvegetable WHERE nombre='".mysqli_real_escape_string($connect,stripcslashes($_POST['nombre']))."'")
or die('Erreur :'.mysqli_error());

if(mysqli_num_rows($name) != 0) {
$doublonName = "The name already exists";
}

if(mysqli_num_rows($nombre) != 0) {
$doublonNombre = "The number already exists";
}

elseif(mysqli_num_rows($name) == 0 && mysqli_num_rows($nombre) == 0) {
$query = mysqli_query($connect,"INSERT INTO fruitandvegetable(id, name, color,description, nombre, type, image_name) VALUES('', '".mysqli_real_escape_string($connect,$_POST['name'])."', '".mysqli_real_escape_string($connect,$color)." ,
'".mysqli_real_escape_string($connect,$type)." ,'".mysqli_real_escape_string($connect,$description)."', '".mysqli_real_escape_string($connect,$_POST['nombre'])."',
'".mysqli_real_escape_string($connect,$image_name)."')")

or die('Erreur :'.mysqli_error($connect));

$erreur = "Votre Fruit Et Legume a bien été pris en compte";

}

最佳答案

缺少

'".mysqli_real_escape_string($connect,$color)." ,

'".mysqli_real_escape_string($connect,$type)." ,

试试这个 -

$query = mysqli_query($connect,"INSERT INTO fruitandvegetable(id, name, color,description, nombre, type, image_name) VALUES('', '".mysqli_real_escape_string($connect,$_POST['name'])."', '".mysqli_real_escape_string($connect,$color)."' ,
'".mysqli_real_escape_string($connect,$type)."' ,'".mysqli_real_escape_string($connect,$description)."', '".mysqli_real_escape_string($connect,$_POST['nombre'])."',
'".mysqli_real_escape_string($connect,$image_name)."')");

关于php - MySQL 中的 INSERT 第二次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26843188/

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