The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> unable to insert data in mySQL, error:nable to add dataYou have an error in your SQL syntax; check the
icy_negi84
post 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 biggrin.gif";

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 biggrin.gif";

mysql_close($conn);
}
?>

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 20th May 2024 - 05:22 PM