You have an error in your SQL syntax

Hi Guys. Again apologies for any glaring error here but im a self confessed noob!

I had a form to post to a database which worked fine but now isnt working since i added a username and password field???

Now im getting the error:
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 ''email,tel,sex,username,password`) VALUES (‘James Brown’, ‘15’, ’ at line 1

Below is the form post:

[php]

  </tr>
  <tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="4"><input type="submit" value="Submit"/></td>
  </tr>
       
  Name:  
    <input type="text" name="firstname" />
    </td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>Age:</td>
  <td>&nbsp;</td>
  <td colspan="4">
    <input type="text" name="age" />
    </td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>Email: </td>
  <td>&nbsp;</td>
  <td colspan="4">
    <input type="text" name="email" />
    </td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>Phone No.:</td>
  <td>&nbsp;</td>
  <td colspan="4">
    <input type="text" name="tel" />
    </td>
  </tr>
  
<tr>
  <td>&nbsp;</td>
  <td>Sex: </td>
  <td>&nbsp;</td>
  <td width="20"><input type="radio" name="sex" value="male"/></td>
  <td width="39">Male</td>
  <td width="21"><input type="radio" name="sex" value="Female"/></td>
  <td width="144">Female</td>
  </tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="4">&nbsp;</td>
  </tr>
<!--<tr>
  <td>&nbsp;</td>
  <td>Photo</td>
  <td>&nbsp;</td>
  <td colspan="4"><input type="file" name="image" /></td>
  </tr> 
  <tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="4">&nbsp;</td>
  </tr>-->
<tr>
  <td>&nbsp;</td>
  <td>Username:</td>
  <td>&nbsp;</td>
  <td colspan="4"><input type="text" name="username"/></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td valign="top">Password:</td>
  <td>&nbsp;</td>
  <td colspan="4">
  <div class='pwdwidgetdiv' id='thepwddiv'></div>
[/php]

Sorry for the length

and her is the file which should insert it into the database:

[php]<?php
if ($_POST[‘firstname’]!=""){
// Connects to your Database
require(“db_con.php”);

//Table Selected

mysql_select_db(“chaletpa_personals”,$dbhandle)
or die(“Could not select personals”);

//This is the directory where images will be saved
#$target = “customer_images/”;
#$target = $target . basename( $_FILES[‘image’][‘name’]);
#$ok=1;

//This gets all the other information from the form
$firstname=$_POST[‘firstname’];
$age=$_POST[‘age’];
#$pic=($_FILES[‘image’][‘name’]);
$email=$_POST[‘email’];
$tel=$_POST[‘tel’];
$sex=$_POST[‘sex’];
$myusername=$_POST[‘username’];
$mypassword=$_POST[‘password’];

// encrypt password
$encrypted_mypassword=md5($mypassword);

//Writes the information to the database
mysql_query(“INSERT INTO details (name, age, ‘email,tel,sex,username,password`)
VALUES (’$firstname’, ‘$age’, ‘$email’, ‘$tel’, ‘$sex’, ‘$myusername’, ‘$encrypted_mypassword’)”) or die(mysql_error()) ;

$message = “Thank you, you have now been added to our database!”;
}else{
$message = “You did not complete the form!”;
};
require (“incs/header.php”);
?>

<?php echo $message;?>
<?php

require (“incs/footer.php”);

?>
[/php]

Any advise would be great as ive tried different syntax methods with the same result :frowning:

Cheers in advance!

My guess would be that age is an integer on the database in which case your query line should be:

[php]
mysql_query(“INSERT INTO details (name, age, ‘email,tel,sex,username,password`)
VALUES (’$firstname’, $age, ‘$email’, ‘$tel’, ‘$sex’, ‘$myusername’, ‘$encrypted_mypassword’)”) or die(mysql_error()) ;
[/php]

If it is an integer you don’t put the value in apostrophe’s as those are used for strings.

Thanks RaythXC. This is another query answered and another learning curve.

Thanks again for all your help! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service