Jump to content

Mysql Insert Query


Amit20

Recommended Posts

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!

 

 

Link to comment
https://forums.phpfreaks.com/topic/247461-mysql-insert-query/
Share on other sites

$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.

Link to comment
https://forums.phpfreaks.com/topic/247461-mysql-insert-query/#findComment-1270773
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.