Jump to content

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.