ivanAdolfo Posted February 18 Share Posted February 18 insertImg: $sql="`user`, `id`, `imageName`, `imageType`, `imageSize`, `imgeContent`) VALUES ($wuser,$id, $imgName, $imgType, $imgSize,$imgContent)"; Values: XY(user varchar)=1(id int)=noticiacallampa.jpg(imageName varchar)=image/jpeg(imageType varchar)=31 kB(imageSize varchar)=imgContent (longlob it comes from file_get_contents($image) Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'kB,????' at line 5 in C:\xampp\htdocs\_website\liceoUtil\php\liceoFuncs.php:79 Stack trace: #0 C:\xampp\htdocs\_website\liceoUtil\php\liceoFuncs.php(79): mysqli_query(Object(mysqli), 'INSERT INTO `li...') #1 C:\xampp\htdocs\_website\liceoIUpload.php(32): insertImg(Object(mysqli)) #2 {main} thrown in C:\xampp\htdocs\_website\liceoUtil\php\liceoFuncs.php on line 79 line 79: $result = mysqli_query($conn, $sql); thanks Quote Link to comment https://forums.phpfreaks.com/topic/318275-uncaught-mysqli_sql_exception/ Share on other sites More sharing options...
Barand Posted February 18 Share Posted February 18 An insert query works better if your sql informs the server it's an INSERT query which table to insert into so needs to begin with "INSERT INTO tablename..." Also, string literals like $imageName need to be inside single quotes. However you should be using a prepared statement. I would also advise storing your image files in the filesystem and putting the metadata (such as filename) in the table. Quote Link to comment https://forums.phpfreaks.com/topic/318275-uncaught-mysqli_sql_exception/#findComment-1615935 Share on other sites More sharing options...
ivanAdolfo Posted February 19 Author Share Posted February 19 21 hours ago, Barand said: An insert query works better if your sql informs the server it's an INSERT query which table to insert into so needs to begin with "INSERT INTO tablename..." Also, string literals like $imageName need to be inside single quotes. However you should be using a prepared statement. I would also advise storing your image files in the filesystem and putting the metadata (such as filename) in the table. I try it using quotes as well and the INTO 'tablename' and the error still the same. I will do what you suggest... storing your image files in the filesystem and putting the metadata (such as filename) in the table. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/318275-uncaught-mysqli_sql_exception/#findComment-1615996 Share on other sites More sharing options...
Barand Posted February 19 Share Posted February 19 Post the output from... echo $sql; Quote Link to comment https://forums.phpfreaks.com/topic/318275-uncaught-mysqli_sql_exception/#findComment-1615997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.