joshgarrod Posted January 28, 2009 Share Posted January 28, 2009 Hi, i have a script that is "supposed" to submit data to my databse, but it is not working. I can't figure out why, the error tells me it is something to do with my sql syntax? <?php error_reporting (E_ALL ^ E_NOTICE); $usr = "ust"; $pwd = "pword"; $db = "db"; $host = "ipad"; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } if ($_POST['submit']) { $title = mysql_real_escape_string($_POST['title']); $desc = mysql_real_escape_string($_POST['desc']); $partno = mysql_real_escape_string($_POST['partno']); $price = mysql_real_escape_string($_POST['price']); $avail = mysql_real_escape_string($_POST['avail']); $image = mysql_real_escape_string($_POST['image']); $SQL = " INSERT INTO spares"; $SQL .= " (title, desc, partno, price, avail, image) VALUES "; $SQL .= " ('$title', '$desc', '$partno', '$price', '$avail', '$image') "; $result = mysql_db_query($db,$SQL,$cid); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P><B>Your itemhas been added to our classified section</B></P>\n"); } ?> Link to comment https://forums.phpfreaks.com/topic/142777-submitting-data-to-database-with-html-form/ Share on other sites More sharing options...
kittrellbj Posted January 28, 2009 Share Posted January 28, 2009 First, I would remove whitespace from in front of INSERT, and it might be printing an extra whitespace between VALUES and the ( on the next line. Also, I format my SQL queries a little differently. If I was doing it, the third SQL line would look like this: $SQL .= "('" . $title . "'. '" . $desc . "', '" . $partno . "', '" . $price . "', '" . $avail . "'. '" $image . "')"; That may be what is causing it also. Try echo $SQL; before your mysql die section to see if it is formatting your SQL the way it needs to be inserted into the database. Link to comment https://forums.phpfreaks.com/topic/142777-submitting-data-to-database-with-html-form/#findComment-748379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.