DanielHardy Posted February 24, 2009 Share Posted February 24, 2009 I'm probably going blind due to looking at this script all day long! The script was previously working fine and adding users to the database. I have added a few die clauses in and suddenly it does not add users to the database (although the script runs fine without any errors) Could someone spot what I have missed? <?php include "page.class"; $Sample = new Page; $Content = " <HTML> <BODY> </BODY> </HTML>"; $Sample->Title = "Please Join Our Site!"; $Sample->Keywords = "PHP, Classes"; $Sample->SetContent( $Content ); $Sample->Display( ); ?> <?php // Connects to my Database "db0607197" mysql_connect("localhost", "0607197", "12345") or die(mysql_error()); mysql_select_db("db0607197") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM Users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('<div class="clean">Sorry, the username '.$_POST['username'].' is already in use.Pick Another One</a>'); } // Check if passwords match if ($_POST['pass'] != $_POST['pass2']) { die('<div class="clean">Your passwords did not match. '); } // encrypt the password $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } include "email.class"; $class1 = &New Class1; $class1->Email = $_POST['email']; $check_email = $class1->check_email(); if(!$check_email){die ('The email address is not valid! '); } include "username.class"; $username = &New Username; $username->Check = $_POST['username']; $check_username = $username->check_username(); if(!$check_username){die ('Please enter a username '); } include "password.class"; $password = &New Password; $password->Check4 = $_POST['firstname']; $check_password = $password->check_password(); if(!$check_password){die ('Please enter a password '); } include "firstname.class"; $firstname = &New Firstname; $firstname->Check5 = $_POST['lastname']; $check_firstname = $firstname->check_firstname(); if(!$check_firstname){die ('Please enter a firstname '); } // Insert the new users info into the database $insert = "INSERT INTO Users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')"; $add_member = mysql_query($insert); ?> <div class="clean"><h1>Successfully Registered</h1></div> <!-- Form to capture Register Information --> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table width="200" border="0" class="centeredtable" > <tr><td colspan=2><h1>Register</h1></td></tr> <tr><td>First Name:</td><td> <input type="text" name="lastname" maxlength="60"> </td></tr> <tr><td>Last Name:</td><td> <input type="text" name="firstname" maxlength="60"> </td></tr> <tr><td>Email:</td><td> <input type="text" name="email" maxlength="60"> </td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> Already Registered? <a href="login.php">Log In</a> Thanks in advance Dan Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/ Share on other sites More sharing options...
jonsjava Posted February 24, 2009 Share Posted February 24, 2009 I'd be glad to help, but you ripped some code out, and I have no idea if my code flow is remotely accurate to how it is supposed to work. I don't like putting closing brackets in unless I know that's where they are supposed to go. Please post all the code (removing any sensitive data and replacing it with ******** or something). Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770513 Share on other sites More sharing options...
DanielHardy Posted February 24, 2009 Author Share Posted February 24, 2009 Sorry you have confused me now. This is the whole code, php wise anyway Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770525 Share on other sites More sharing options...
DanielHardy Posted February 24, 2009 Author Share Posted February 24, 2009 Also getting an unexpected end message too now Any help, again, greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770527 Share on other sites More sharing options...
imperialized Posted February 24, 2009 Share Posted February 24, 2009 Your problem lies here: // Insert the new users info into the database $insert = "INSERT INTO Users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')"; $add_member = mysql_query($insert); you need to be sure you have all the fields for example: // Insert the new users info into the database $insert = "INSERT INTO Users (username, password, firstname, lastname, email) <--- here VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')"; $add_member = mysql_query($insert); you could also add this: $add_member = mysql_query($insert) or DIE("Error Occured :" . mysql_error()); this will tell you if the query has failed. Edit: the $end error is due to a miss } you need to add one at the bottom if (isset($_POST['submit'])) { this block is not closed, add it here: $add_member = mysql_query($insert); } <-- ?> Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770529 Share on other sites More sharing options...
DanielHardy Posted February 24, 2009 Author Share Posted February 24, 2009 of corse!thankyou! However I can't do anything at the moment as I am still getting whacked with the unexpected end message. Can you see where I've done this? Sorry to sound like a dunce but my head hurts! Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770533 Share on other sites More sharing options...
imperialized Posted February 24, 2009 Share Posted February 24, 2009 Check my above post, that should do it. I gotta go to class, so I cant help any further at the moment.. Good luck with your coding Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770534 Share on other sites More sharing options...
DanielHardy Posted February 24, 2009 Author Share Posted February 24, 2009 Thank **** for that. As always it seems huge problems arise by failing to notice the smallest things! Thanks for all your help. All is good in Dan world! Quote Link to comment https://forums.phpfreaks.com/topic/146753-info-not-adding-to-database/#findComment-770537 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.