Jump to content

Recommended Posts

I am creating a registration form for my website, and I keep getting an insert error when I submit the registration form. The registration page is very simple it assigns a user a random customer key, a username and a password. I have used this same insert syntax in other forms before, but for some reason I keep getting an error here. Help?

 

Error: 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 'key,username,password) VALUES ('1559802062','name','password')' at line 1

 

Code:

<?php

 

include 'connect.php';

 

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

$key=$_POST[key];

 

$sql="INSERT INTO logins (key, username, password)

VALUES

('$key','$_POST[username]','$_POST[password]')";

 

if (!mysql_query($sql))

  {

  die('Error: ' . mysql_error());

  }

echo "You have successfully registered!";

 

?>

 

I have checked the syntax so many times and I can't find this illusive error. Anyone have suggestions?

 

 

Link to comment
https://forums.phpfreaks.com/topic/161690-insert-error-beginner-needs-help/
Share on other sites

I changed the term for "key" to customercode and added the new die syntax and it worked perfectly. Thanks guys!

 

Good.  You could have still kept the same field name but just put backticks around it.

 

$sql="INSERT INTO logins (`key`, username, password)

 

You should take out the or die clause when putting this on your production server.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.