unable to insert data in mySQL, error:nable to add dataYou have an error in your SQL syntax; check the |
unable to insert data in mySQL, error:nable to add dataYou have an error in your SQL syntax; check the |
icy_negi84 |
May 21 2014, 01:52 PM
Post
#1
|
Group: Members Posts: 8 Joined: 21-May 14 Member No.: 20,958 |
I'm new in PHP getting error while inserting data
error: Unable to add data 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 ''')' at line 1 my code: <?php if(isset($_POST['add'])) { $dbhost='localhost'; $dbuser='root'; $dbpass='ricky'; $conn=mysql_connect($dbhost,$dbuser,$dbpass); if(!$conn) { die('unable to connect to database' .mysql_error()); } /* if(! get_magic_quotes_gpc()) { $Name=addslashes($_POST['Name']); $Email=addcslashes($_POST['Email']); $Contact=addcslashes($_POST['Contact']); $messgae=addcslashes($_POST['message']) } else { $Name=$_POST['Name']; $Email=$_POST['Email']; $Contact=$_POST['Contact']; $messgae=$_POST['message']; }*/ $sql="INSERT INTO contact1". "(Name,Email,Contact,message)". "VALUES('$Name','$Email',$Contact,'$message')"; mysql_select_db('hotel'); $retval=mysql_query($sql,$conn); if(! $retval) { die('Unable to add data' .mysql_error()); } echo "Thank you for contacing us "; mysql_close($conn); } ?> or I tried this also: <?php if(isset($_POST['add'])) { $dbhost='localhost'; $dbuser='root'; $dbpass='ricky'; $conn=mysql_connect($dbhost,$dbuser,$dbpass); if(!$conn) { die('unable to connect to database' .mysql_error()); } /* if(! get_magic_quotes_gpc()) { $Name=addslashes($_POST['Name']); $Email=addcslashes($_POST['Email']); $Contact=addcslashes($_POST['Contact']); $messgae=addcslashes($_POST['message']) } else { $Name=$_POST['Name']; $Email=$_POST['Email']; $Contact=$_POST['Contact']; $messgae=$_POST['message']; }*/ $sql="INSERT INTO contact1". "(Name,Email,Contact,message)". "VALUES('$Name','$Email',$Contact,'$message')"; mysql_select_db('hotel'); $retval=mysql_query($sql,$conn); if(! $retval) { die('Unable to add data' .mysql_error()); } echo "Thank you for contacing us "; mysql_close($conn); } ?> |
Lo-Fi Version | Time is now: 20th May 2024 - 05:22 PM |