timmah1 Posted June 26, 2008 Share Posted June 26, 2008 Can anybody tell me what the error is? $report_date = $_POST['report_date']; $desc = $_POST['desc']; $air = $_POST['air']; $lodge = $_POST['lodge']; $fuel = $_POST['fuel']; $phone = $_POST['phone']; $meals = $_POST['meals']; $ent = $_POST['ent']; $other = $_POST['other']; $o_desc = $_POST['o_desc']; $scanned = $_POST['scanned']; $report_date = stripslashes($report_date); $desc = stripslashes($desc); $air = stripslashes($air); $lodge = stripslashes($lodge); $fuel = stripslashes($fuel); $phone = stripslashes($phone); $meals = stripslashes($meals); $ent = stripslashes($ent); $other = stripslashes($other); $o_desc = stripslashes($o_desc); $scanned = stripslashes($scanned); $report_date = mysql_real_escape_string($report_date); $desc = mysql_real_escape_string($desc); $air = mysql_real_escape_string($air); $lodge = mysql_real_escape_string($lodge); $fuel = mysql_real_escape_string($fuel); $phone = mysql_real_escape_string($phone); $meals = mysql_real_escape_string($meals); $ent = mysql_real_escape_string($ent); $other = mysql_real_escape_string($other); $o_desc = mysql_real_escape_string($o_desc); $scanned = mysql_real_escape_string($scanned); $user_id = $_SESSION['SESS_USERID']; echo " id: $user_id<br> report for: $report_date<br> desc: $desc <br> air: $air <br> lodge: $lodge <br> fuel: $fuel <br> phone: $phone <br> meals: $meals <br> ent: $ent <br> other: $other <br> other desc: $o_desc <br> scans: $scanned <br><br>"; $expense = "INSERT INTO expense(user_id, date_added, report_date, desc, air, lodge, fuel, phone, meals, ent, other, o_desc, scanned) VALUES( '$user_id', NOW(), '$formatted_date', '$desc', '$air', '$lodge', '$fuel', '$phone', '$meals', '$ent', '$other', '$o_desc', '$scanned');"; mysql_query($expense) or die("<br>Sorry, there was a problem creating this expense account<br> ".mysql_error()); Everything echos out correctly, but it won't insert into the database. Here is what I get, but I cannot find the error Sorry, there was a problem creating this expense account 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, air, lodge, fuel, phone, meals, ent, other, o_desc, scanned) VALUES( ' at line 1 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/ Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 desc is a reserved word in mysql, put backticks around it: $expense = "INSERT INTO expense(user_id, date_added, report_date, `desc`, air, lodge, fuel, phone, meals, ent, other, o_desc, scanned) VALUES( '$user_id', Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/#findComment-575119 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 put backticks around desc like so `desc` the problem is that desc is a reserved word. Though I really recommend you change it to a different name instead of using backticks, as only mysql will support that. And even still, it's just bad coding to use reserved words as column names. Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/#findComment-575120 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 desc is reserved for DESCending. try this... mysql_query("INSERT INTO `expense` (`user_id`, `date_added`, `report_date`, `desc`, `air`, `lodge`, `fuel`, `phone`, `meals`, `ent`, `other`, `o_desc`, `scanned`) VALUES('$user_id',NOW(),'$formatted_date','$desc','$air','$lodge','$fuel','$phone', '$meals','$ent','$other','$o_desc','$scanned')"); desc is a reserved tem by MySQL. Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/#findComment-575121 Share on other sites More sharing options...
timmah1 Posted June 26, 2008 Author Share Posted June 26, 2008 ok, simple mistake, didn't realize desc was reserved. I changed the column name and now it works. thanks for the help Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/#findComment-575127 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 for future reference: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/#findComment-575131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.