Kia Posted December 18, 2005 Share Posted December 18, 2005 **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 Quote Link to comment https://forums.phpfreaks.com/topic/3068-insert-doesnt-insert/ Share on other sites More sharing options...
Cook Posted December 19, 2005 Share Posted December 19, 2005 [!--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... Quote Link to comment https://forums.phpfreaks.com/topic/3068-insert-doesnt-insert/#findComment-10255 Share on other sites More sharing options...
Kia Posted December 19, 2005 Author Share Posted December 19, 2005 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. Quote Link to comment https://forums.phpfreaks.com/topic/3068-insert-doesnt-insert/#findComment-10258 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.