rjcfan4ever Posted July 6, 2011 Share Posted July 6, 2011 My registration form fails if I wanna sign up he says this: Error Sorry, your registration failed. Please go back and try again. Here is the code of register.php: <?php include "base.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User Management System (Tom Cameron for NetTuts)</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="main"> <?php if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $email = mysql_real_escape_string($_POST['email']); $checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($checkusername) == 1) { echo "<h1>Error</h1>"; echo "<p>Sorry, that username is taken. Please go back and try again.</p>"; } else { $registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')"); if($registerquery) { echo "<h1>Success</h1>"; echo "<p>Your account was successfully created. Please <a href=\"index2.php\">click here to login</a>.</p>"; } else { echo "<h1>Error</h1>"; echo "<p>Sorry, your registration failed. Please go back and try again.</p>"; } } } else { ?> <h1>Register</h1> <p>Please enter your details below to register.</p> <form method="post" action="register.php" name="registerform" id="registerform"> <fieldset> <label for="username">Username:</label><input type="text" name="username" id="username" /><br /> <label for="password">Password:</label><input type="password" name="password" id="password" /><br /> <label for="email">Email Address:</label><input type="text" name="email" id="email" /><br /> <input type="submit" name="register" id="register" value="Register" /> </fieldset> </form> <?php } ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/ Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 your'e missing a parenthesis if(mysql_num_rows($checkusername) == 1) { echo "<h1>Error</h1>"; echo "<p>Sorry, that username is taken. Please go back and try again.</p>"; } Edit: hold on.... Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239185 Share on other sites More sharing options...
rjcfan4ever Posted July 6, 2011 Author Share Posted July 6, 2011 haaha XD ty very much EDIT: I am just 12 years old Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239188 Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 I would check to make sure that the user has clicked the submit button before parsing this. <?php if(isset($_POST['register'])){ if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $email = mysql_real_escape_string($_POST['email']); Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239193 Share on other sites More sharing options...
rjcfan4ever Posted July 6, 2011 Author Share Posted July 6, 2011 Sorry but I still have the same error Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239198 Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 Since you are receving that specific error, something lmust be going wrong with your query. Try to debug it $registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239199 Share on other sites More sharing options...
rjcfan4ever Posted July 6, 2011 Author Share Posted July 6, 2011 Ty, and then he says I need to something adjust in phpmyadmin I did it and it works thank you Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239213 Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 Ty, and then he says I need to something adjust in phpmyadmin I did it and it works thank you cool, no problem Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239215 Share on other sites More sharing options...
rjcfan4ever Posted July 6, 2011 Author Share Posted July 6, 2011 hmm... the next problem I chagned the primary key in 0 but.. he automaticaly go's to 11 Quote Link to comment https://forums.phpfreaks.com/topic/241245-my-registration-form-fails/#findComment-1239216 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.