Problem in php database record....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
099prastana
Forum Newbie
Posts: 2
Joined: Mon Oct 12, 2009 11:40 pm

Problem in php database record....

Post by 099prastana »

I encountered a problem when i was going to record a database for my project through cms code . I use easyphp and I want to save database through the site itself. but the following error occured when i gave datas Like name-john address 7th floor .and so on.......

Could not add recordYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"advertising_agencies" value ("John","7th floor","124564687546")

my code:-

$sql= 'insert into "'.$table.'" value ("'.$_POST['name_txt'].'","'.$_POST['add_txt'].'","'.$_POST['phone_txt'].'")';

if(!mysql_query($sql,$con))
{
die('Could not add record' . mysql_error());
}
else
{
print "Record Added Sucessfully";
include 'setting_form.php';
}



}
}
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Problem in php database record....

Post by Weiry »

Please when posting, wrap your code using the code/php tags.

Your SQL query has a syntax error in it. You dont use ' or " around your table names, you should use ` if your going to encase table names or fields. Also, your SQL has "value" which is not the correct syntax, the correct would be "values"
Try this:

Code: Select all

$sql= "INSERT INTO `{$table}` VALUES ('{$_POST['name_txt']}', '{$_POST['add_txt']}', '{$_POST['phone_txt']}')";
099prastana
Forum Newbie
Posts: 2
Joined: Mon Oct 12, 2009 11:40 pm

Re: Problem in php database record....

Post by 099prastana »

using that code following error has been displayed.

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 'table_name' values ('name1','name2','name3')
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Problem in php database record....

Post by Weiry »

Weiry wrote:dont use ' or " around your table names, you should use ` if your going to encase table names or fields.
099prastana wrote: 'table_name' values
Post Reply