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 Quote 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', Quote 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. Quote 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. Quote 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 Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/112040-solved-insertion-error/#findComment-575131 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.