I keep getting this error when trying to connect to mysql Error: 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 'desc, img, pdf, ccore, ccore_var) VALUES ('writing','friendly letters','hearts f' at line 1 Code (markup): Does anyone know what I am doing wrong?
Yes. Thanks <?php $con = mysql_connect("localhost","sshirk_tf","tfdb1"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sshirk_teachfuzz", $con); $sql="INSERT INTO worksheets (id, subject, category, title, desc, img, pdf, ccore, ccore_var) VALUES ('$_POST[id]','$_POST[subject]','$_POST[category]','$_POST[title]','$_POST[desc],''$_POST[jpeg]','$_POST[pdf]','$_POST[ccore]','$_POST[ccore_var]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> Code (markup): It returns this error: Error: 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 'desc, img, pdf, ccore, ccore_var) VALUES ('','reading','Comprehension','Book Rep' at line 1
On line 12, there's a comma in the wrong place. '$_POST[desc],''$_POST[jpeg]', Code (markup): Should be: '$_POST[desc]','$_POST[jpeg]', Code (markup): Additionally, mysql_connect is deprecated, see here, http://php.net/manual/en/function.mysql-connect.php so maybe you can also try using one of the mentioned alternatives. mysqli_connect() PDO::__construct()
Hi Colleen, I tried the msqli_connect and was successful at making a connection. <?php /* Connect to an ODBC database using driver invocation */ $dsn = 'mysql:dbname=sshirk_teachfuzz;host=184.173.226.215'; $user = 'sshirk_tf'; $password = 'tfdb1'; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> Code (markup): Question now is. How do I combine that connection piece of code into the form from the above post? Thanks
Look at the error message. desc is a reserved word. If you can't redo your table to use a different field name, quote the field name.
Thanks Rukbat, I actually figured that out and got it corrected. However I have a new issue. See this post: https://forums.digitalpoint.com/threads/php-form-to-db.2635656/ Thanks again.