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';
}
}
}
Problem in php database record....
Moderator: General Moderators
-
099prastana
- Forum Newbie
- Posts: 2
- Joined: Mon Oct 12, 2009 11:40 pm
Re: Problem in php database record....
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:
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....
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')
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')
Re: Problem in php database record....
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