dopod0901
2014-11-10 11:50
浏览 18
已采纳

MySQL中的INSERT第二次不起作用

I have a problem with a MySQL request. Insertion doesn't work overnight. I don't know why. it is second time he doing this.

I am getting the following 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";  

}

图片转代码服务由CSDN问答提供 功能建议

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

我收到以下mysqli_error:

Erreur:您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第1行“1”,“ljhb”,“5456”,“0-aVeeRYLr-fruits-et-legumes-bio-”附近使用正确的语法 \ n

  $ connect = mysqli_connect(“localhost”,“root”,“”,“db”); 
 $ name = mysqli_query($ connect,“SELECT name FROM  fruitandvegetable WHERE name ='“。mysqli_real_escape_string($ connect,stripcslashes($ _ POST ['name']))。”'“)
或die('Erreur:'。mysqli_error()); 
 $ nombre = mysqli_query(  $ connect,“SELECT nombre FROM fruitandvegetable WHERE nombre ='”。mysqli_real_escape_string($ connect,stripcslashes($ _ POST ['nombre']))。“'')
或者死('Erreur:'。mysqli_error());  
 
 
(mysqli_num_rows($ name)!= 0){
 $ doublonName =“名称已经存在”; 
} 
 
if(mysqli_num_rows($ nombre)!= 0){
 $ doublonNombre =  “数字已经存在”; 
} 
 
 
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)。“')”)
 
或者死('Erreur:'。mysqli_error($ connect));  
 
 $ erreur =“Votre Fruit Et Legume abienétéprisen en compte”;  
 
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongsi1944 2014-11-10 11:53
    已采纳

    Missing 's.

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

    Try this -

    $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)."')");
    
    点赞 打赏 评论
  • douhuantui6259 2014-11-10 11:57
    '".mysqli_real_escape_string($connect,$color)." ,
    

    replace above with below

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

    and this

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

    with

    '".mysqli_real_escape_string($connect,$type)."'
    
    点赞 打赏 评论