Jump to content

Archived

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

Kia

INSERT doesn't INSERT?

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

Share this post


Link to post
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...

 

 

Share this post


Link to post
Share on other sites

Thank you

 

that solved the problem, guess that's what I get for staring at lines of code for several hours straight.

 

Cheers, much appreciated.

Share this post


Link to post
Share on other sites

×

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.