Jump to content

[SOLVED] Insertion error


timmah1

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.