Jump to content

INSERT doesn't INSERT?


Kia

Recommended Posts

**SOLVED**

 

Part of a registration code I am using saves user details into a mysql database.

 

the database is there and has access (logins can be called from the database).

the user fills in a basic form and the details are supposed to be entered into the database.

 

join.php

$query="INSERT INTO users (uid, username, password, first_name, last_name, country, email, last_paid, signup_date) VALUES ('','$susername', '$spassword', '$sfirst_name', '$slast_name', '$scountry', 'free', '$nowdate')";
            mysql_query($query);

 

join.php calls another .php early on which contains the database login details.

the user gets a "success screen" and their randomly generated password is emailed to them (this bit works), however the details never make it into the database.

 

the login screen (I have manually entered several users for test purposes) uses the same .php file to get it's database login info and successfully completes queries to validate the user info.

 

any suggestions welcomed

Link to comment
Share on other sites

[!--quoteo(post=328422:date=Dec 19 2005, 06:06 AM:name=Kia)--][div class=\'quotetop\']QUOTE(Kia @ Dec 19 2005, 06:06 AM) 328422[/snapback][/div][div class=\'quotemain\'][!--quotec--]

$query="INSERT INTO users (uid, username, password, first_name, last_name, country, email, last_paid, signup_date) VALUES ('','$susername', '$spassword', '$sfirst_name', '$slast_name', '$scountry', 'free', '$nowdate')";
            mysql_query($query);

 

I see two problems.

 

1- The number of values does not match the number of fields.

2- If uid is an auto-inc field, you're actually better off leaving it out of the list of fields (then of course you don't provide a value for it) and let MySQL take care of it automatically for you.

 

And a comment: it is a good idea, and actually best practice, to enclose identifiers with backticks in MySQL queries, so that in case you're using a reserved MySQL word as an identifier, MySQL still treats it as an identifier and does not complain:

 

$query = "INSERT INTO `users` (`username`, `password`, `first_name`, `last_name`, `country`, `email`, `last_paid`, `signup_date`) VALUES ('$susername', '$spassword', '$sfirst_name', '$slast_name', '$scountry', '$semail', 'free', '$nowdate')";
mysql_query($query);

 

NB: I assumed email would be stored in $semail...

 

 

Link to comment
Share on other sites

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.