SQL Syntax Error (Server version: 5.6.17 - MySQL)

前端 未结 3 736
别跟我提以往
别跟我提以往 2021-01-29 09:45


Could you guys please tell me what is missing on this code. because i get SQL Syntax Error.

i have created table with three colums. ID is auto incriminating and Ima

相关标签:
3条回答
  • 2021-01-29 10:19

    You are trying to insert the value '$img_name' as Name and not img_name content. Try the following:

     $query  = mysqli_query($Con, "INSERT INTO `cars_tbl` (ID,Name,Image) VALUES ('','" . $img_name . "','" . $image . "')");
    
    0 讨论(0)
  • 2021-01-29 10:28

    You forgot to wrap $img_name in '

    $query = mysqli_query($Con, "INSERT INTO `cars_tbl` (ID, Name, Image) VALUES ('', '$img_name', '$image')");
    
    0 讨论(0)
  • 2021-01-29 10:33

    The problem is you are saving apparently blob into the database without escaping it.

    You must realize what happens in your command: The image data - which can also contain ' because it is binary - invalidates your SQL command.

    The correct way how to save it:

    1)

    Either with prepared statements

    2)

    mysqli_query($Con, "INSERT INTO `cars_tbl` (ID, Name, Image)
       VALUES ('', '$img_name', '".mysqli_escape_string($image)."')");
    

    I would prefer Prepared Statements. The other question is why you set ID to an empty string.

    0 讨论(0)
提交回复
热议问题