Kryllster Posted April 12, 2010 Share Posted April 12, 2010 This code is almost a carbon copy of code that works. I am trying to create a simple account creation script and I have been working on it trying different things and still cant insert the data into the mysql database. Here is the code. <?php $message = "Please do NOT leave any fields empty Thank You!!"; $nickname = $_POST['nickname']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $password = $_POST['password']; $email = $_POST['email']; if ( empty($_POST['nickname']) || empty($_POST['firstname']) || empty($_POST['lastname']) || empty($_POST['password']) || empty($_POST['email']) ) { echo $message; exit(); } // connect to database include('scripts/db_config.php'); // Test for duplicate Username. If True then back to form. If not continue. $sql = "select * from $tbl_name where nickname='" . $_POST['nickname'] . "'"; $result = mysql_query($sql); if (mysql_num_rows($result) >= 1) { echo "That Nickname is already taken please choose another!"; exit(); } // continue if all these checks are ok Im hoping else { // Populate table from form and defined info mysql_query("INSERT INTO $tbl_name (nickname, firstname, lastname, password, email) VALUES('$nickname','$firstname','$lastname','$password','$email')"); // Close Database mysql_close(); // Direct on Creation Success header("Location:index.php?show=success"); } ?> Any ideas why this may not be working properly? Quote Link to comment https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2010 Share Posted April 12, 2010 You haven't exactly told us what it IS doing, in order to pin down which of the dozen possible things that could be going wrong. What do you see in front of you when you submit the form? Quote Link to comment https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/#findComment-1040211 Share on other sites More sharing options...
Kryllster Posted April 12, 2010 Author Share Posted April 12, 2010 Well when I fill in the form then click submit it goes to the success page but when I check the database the information isnt entered. I get no error messages. Just an empty database. Quote Link to comment https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/#findComment-1040213 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2010 Share Posted April 12, 2010 Temporarily comment out the header() redirect statement and echo mysql_error() on the next line following the mysql_query() statement to find out why the query failed. Quote Link to comment https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/#findComment-1040215 Share on other sites More sharing options...
Kryllster Posted April 12, 2010 Author Share Posted April 12, 2010 I did as you told me to and found out there was a field missing in my database sql file I had uploaded. the error said that I was missing field password in my sql. It is fixed now thanks, poor oversight on my part sorry to waste your time. Quote Link to comment https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/#findComment-1040218 Share on other sites More sharing options...
scottnicol Posted April 12, 2010 Share Posted April 12, 2010 Not sure, but aren't you missing an 'else'? Quote Link to comment https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/#findComment-1040219 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.