akiznin Posted June 23, 2009 Share Posted June 23, 2009 I created a basic register script to see what I have learned so far but why wont it submit the username and password into the database? I get no errors in the script or the database, it just does not submit it. <?php include('../database.php'); $session = $_SESSION['username']; if (isset($session)) { header('Location: ../index.php'); } $username = $_POST['username']; $password = $_POST['password']; if (!isset($username) OR !isset($password) OR !ctype_alnum($username) OR !ctype_alnum($password) OR strlen($username) > 20 OR strlen($username) < 3 OR strlen($password) > 20 OR strlen($password) > 3) { echo "<form method=\"post\" action=\"index.php\">\n"; echo "Username: <input type=\"text\" size=\"10\" maxlength=\"20\" name=\"name\"> <br />\n"; echo "Password: <input type=\"password\" size=\"10\" maxlength=\"20\" name=\"password\"><br />\n"; echo "\n"; echo "<input type=\"submit\" value=\"Register\"> \n"; echo "</form>\n"; } else { $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql=mysql_query("SELECT * FROM `members` WHERE username='$username'"); $count=mysql_num_rows($sql); if($count == 1) { echo "Username has been taken."; } else { $password_md5 = md5($password); $query = "INSERT INTO members (id, username, password) VALUES ('', '$username', '$password_md5')"; $results = mysql_query($query); if ($results) { echo "Thank you for registering, " . htmlentities($username) . "!"; } mysql_close(); } } ?> Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/ Share on other sites More sharing options...
priti Posted June 23, 2009 Share Posted June 23, 2009 what is the error you are facing? Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861771 Share on other sites More sharing options...
akiznin Posted June 23, 2009 Author Share Posted June 23, 2009 I don't get any error, it just does not submit.. Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861772 Share on other sites More sharing options...
kickstart Posted June 23, 2009 Share Posted June 23, 2009 Hi Take it you are just getting the form presented again. Presume you really want to check the password is more than 3 long and less than 20 long if (!isset($username) OR !isset($password) OR !ctype_alnum($username) OR !ctype_alnum($password) OR strlen($username) > 20 OR strlen($username) < 3 OR strlen($password) > 20 OR strlen($password) > 3) All the best Keith Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861776 Share on other sites More sharing options...
akiznin Posted June 23, 2009 Author Share Posted June 23, 2009 umm... what? that same if statment, nothing changed.. Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861778 Share on other sites More sharing options...
kickstart Posted June 23, 2009 Share Posted June 23, 2009 Hi The highlighted (in red) > sign probably needs to be a < sign. Otherwise if you put in a password of more than 3 characters it will be rejected. All the best Keith Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861779 Share on other sites More sharing options...
akiznin Posted June 23, 2009 Author Share Posted June 23, 2009 I did that, but still it is not inserted into the database.. Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861783 Share on other sites More sharing options...
kickstart Posted June 23, 2009 Share Posted June 23, 2009 Hi What do you get? Redirected to the index page? The form output again? Any of your messages? All the best Keith Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861784 Share on other sites More sharing options...
akiznin Posted June 23, 2009 Author Share Posted June 23, 2009 no errors, just the form again. [EDIT] It has something to do with the if statement, I removed it and it works. But what is wrong with the statement? Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861787 Share on other sites More sharing options...
kickstart Posted June 23, 2009 Share Posted June 23, 2009 Hi Your form field is called name but you are expecting a field called username. All the best Keith Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861790 Share on other sites More sharing options...
akiznin Posted June 23, 2009 Author Share Posted June 23, 2009 omg, it works! thank you sooo much! Link to comment https://forums.phpfreaks.com/topic/163333-solved-mysql-wont-insert-into-database/#findComment-861791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.