我的MySQL请求有问题。插入不会在一夜之间发挥作用。我不知道为什么。这是他第二次这样做。
我收到以下mysqli_error:
Erreur:你的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在第1行“1”,“ljhb”,“5456”,“0-aVeeRYLr-fruits-et-legumes-bio-”附近使用正确的语法
$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";
}
答案 0 :(得分:3)
缺少'
s。
'".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)."')");
答案 1 :(得分:0)
'".mysqli_real_escape_string($connect,$color)." ,
将以上内容替换为
'".mysqli_real_escape_string($connect,$color)."' ,
和这个
'".mysqli_real_escape_string($connect,$type)."
带
'".mysqli_real_escape_string($connect,$type)."'