Amit20 Posted September 19, 2011 Share Posted September 19, 2011 Hello Friends, Now i m stuck with simple insert query . here's the code <?php include_once("conf.php"); $firstName=$_POST['fname']; $lastName=$_POST['lname']; $email=$_POST['email']; $dob=$_POST['dob']; $password=$_POST['pass']; $fname= stripslashes($firstName); $lname=stripslashes($lastName); $mail= mysql_real_escape_string($email); $password= mysql_real_escape_string($password); mysql_select_db('site'); $statement="Insert into Accounts(Name,lastName,emailId,DOB,password) VALUES($fname,$lname,$mail,$dob,$password)"; $query=mysql_real_escape_string($statement); mysql_query($query) or die("Cannot save data:</br> ".mysql_error()); echo "Data Saved Successfully"; ?> Now please explain me why i m getting the following error Cannot save 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 '@gmail.com,1988/12/20,password)' at line 1 Any help will be highly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/247461-mysql-insert-query/ Share on other sites More sharing options...
Pikachu2000 Posted September 19, 2011 Share Posted September 19, 2011 You need to quote the variables that will contain string values in the query string. Quote Link to comment https://forums.phpfreaks.com/topic/247461-mysql-insert-query/#findComment-1270770 Share on other sites More sharing options...
jcbones Posted September 19, 2011 Share Posted September 19, 2011 $query ="Insert into Accounts(Name,lastName,emailId,DOB,password) VALUES('$fname','$lname','$mail','$dob','$password')"; Remove: $query=mysql_real_escape_string($statement); Explanation: Strings sent to MySQL must be enclosed in single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/247461-mysql-insert-query/#findComment-1270773 Share on other sites More sharing options...
Amit20 Posted September 19, 2011 Author Share Posted September 19, 2011 Thank You Pikachu2000 and jcbones. Data Got saved. Thank You Once Again :D Quote Link to comment https://forums.phpfreaks.com/topic/247461-mysql-insert-query/#findComment-1270775 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.