Jump to content

Upload to Database Help


ririe44

Recommended Posts

Hey, I'm getting this 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, amount) VALUES ('NULL','2009-01-01','chk_visa','cat_donations','1','test',' at line 1

 

Here's my code for my database upload file (I've removed the database info, fyi):

<?
$host=host; // Host name
$db_username=username; // Mysql username
$db_password=password; // Mysql password
$db_name=name; // Database name
$tbl_name=table; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$db_username", "$db_password")or die(mysql_error());
mysql_select_db("$db_name")or die(mysql_error());

$exp_date = $_POST['exp_date'];
$exp_chk = $_POST['exp_chk'];
$exp_cat = $_POST['exp_cat'];
$exp_sub_cat = $_POST['exp_sub_cat'];
$exp_description = $_POST['exp_description'];
$exp_amount = $_POST['exp_amount'];

$query = "INSERT INTO $tbl_name (id, date, chk, cat, sub_cat, desc, amount) VALUES ('NULL','".$exp_date."','".$exp_chk."','".$exp_cat."','".$exp_sub_cat."','".$exp_description."','".$exp_amount."')";

if (!mysql_query($query));
{
die('Error: ' . mysql_error());
}
echo "1 record added";
?>

 

What do you think... I've gone through the code 100 times and it all looks good to me!

Link to comment
https://forums.phpfreaks.com/topic/146637-upload-to-database-help/
Share on other sites

Change:

$query = "INSERT INTO $tbl_name (id, date, chk, cat, sub_cat, desc, amount) VALUES ('NULL','".$exp_date."','".$exp_chk."','".$exp_cat."','".$exp_sub_cat."','".$exp_description."','".$exp_amount."')";

to:

$query = "INSERT INTO `$tbl_name` (`id`, `date`, `chk`, `cat`, `sub_cat`, `desc`, `amount`) VALUES ('NULL','".$exp_date."','".$exp_chk."','".$exp_cat."','".$exp_sub_cat."','".$exp_description."','".$exp_amount."')";
echo $query;

 

I believe it's because desc wasn't in the backticks (`) and it is a keyword (for ordering)

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.