Ne.OnZ Posted April 5, 2008 Author Share Posted April 5, 2008 I'm not quite sure I follow you. When you put //insert, do you mean the sql INSERT? If so, then I figure you mean something like this: if($_POST['register'] { //Form code here } elseif(isset($username) || isset($password) || isset($password2) || !empty($username) || !empty($password) || !empty($password2) || !empty($email)) { echo "empty"; } else { //insert } If this is what you meant, how would I display other problems, like the username taken, because I don't see how I can add it in there. Sorry I'm noob D: Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 5, 2008 Share Posted April 5, 2008 no you got it backwards isset and !empty determine if something is not empty or is set. if it is empty or not isset !isset, then it is empty and not isset and it should stop before it is entered. its like telling yoru dark to bark. do you tell it to bark, or tell it to not make any other sounds but bark? Change: <?php else { $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!'; } ?> to <?php elseif(isset($username) || isset($password) || isset($password2) || !empty($username) || !empty($password) || !empty($password2) || !empty($email)) { $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!'; }?> Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 6, 2008 Author Share Posted April 6, 2008 A little confusing, but I get it somewhat. It still won't work though. If I enter a username already taken or not taken, with passwords matching and no email entered, it adds the info to the db. If I leave everything blank, it adds a blank field in the db. If I enter no passwords and/or email it adds to the db. O.O :'( Thanks Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 6, 2008 Share Posted April 6, 2008 can we see your current code ??? if you did it like i had asked there would be no data leaking through. Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 6, 2008 Author Share Posted April 6, 2008 Surely o.o! <div align="center"> <?php require("connect.php"); $db = mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "<br /><br />Registering is disabled right now, please check back later."; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)) echo "The username you entered encountered a problem.<br /><br />"; check($username); if(!$password || !$password2 || !isset($password) || !isset($password2)) echo "The password field cannot be left empty!<br /><br />"; if(!$email) echo "The email you entered encountered a problem.<br /><br />"; if($password != $password2) echo "The passwords you entered do not match.<br /><br />"; elseif(isset($username) || isset($password) || isset($password2) || isset($email) || !empty($username) || !empty($password) || !empty($password2) || !empty($email)) { $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!'; } } } ?> </div> o.o Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 6, 2008 Share Posted April 6, 2008 <?php require("connect.php"); $db = mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "<br /><br />Registering is disabled right now, please check back later."; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)){ die( "The username you entered encountered a problem.<br /><br />"); check($username);} if(!$password || !$password2 || !isset($password) || !isset($password2)){ die ("The password field cannot be left empty!<br /><br />");} if(!$email||empty($email)||!isset($email){ die( "The email you entered encountered a problem.<br /><br />");} if($password != $password2){ die("The passwords you entered do not match.<br /><br />");} }else{ if(isset($password)||!empty($pasword)){ if(isset($username)|!empty($username)){ if(isset($email)|!empty($email)){ $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!';}}} } } ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 6, 2008 Share Posted April 6, 2008 noticed a few small errors Fix: <?php require("connect.php"); $db = mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "<br /><br />Registering is disabled right now, please check back later."; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)){ die( "The username you entered encountered a problem.<br /><br />"); check($username);} if(!$password || !$password2 || !isset($password) || !isset($password2)||empty($password)||empty($password2)){ die ("The password field cannot be left empty!<br /><br />");} if(!$email||empty($email)||!isset($email){ die( "The email you entered encountered a problem.<br /><br />");} if($password != $password2){ die("The passwords you entered do not match.<br /><br />");} }else{ if(isset($password)||!empty($pasword)){ if(isset($username)||!empty($username)){ if(isset($email)||!empty($email)){ $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!';}}} } } ?> Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 6, 2008 Author Share Posted April 6, 2008 I tried the latter version you gave me. The above one. I got an error: Parse error: syntax error, unexpected '{' in /home/divnxn5/public_html/register2.php on line 58 I tried to clean it up: <?php require("connect.php"); $db = mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "<br /><br />Registering is disabled right now, please check back later."; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)) { die("The username you entered encountered a problem.<br /><br />"); check($username); } if(!$password || !$password2 || !isset($password) || !isset($password2) || empty($password) || empty($password2)) { die ("The password field cannot be left empty!<br /><br />"); } if(!$email || empty($email) || !isset($email)) { die("The email you entered encountered a problem.<br /><br />"); } if($password != $password2) { die("The passwords you entered do not match.<br /><br />"); } } else { if(isset($password) || !empty($pasword)) { if(isset($username) || !empty($username)) { if(isset($email) || !empty($email)) { $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!'; } } } } } ?> I got this error: Parse error: syntax error, unexpected T_ELSE in /home/divnxn5/public_html/register.php on line 72 I looked through the code, but I don't see anything that shouldn't belong. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2008 Share Posted April 6, 2008 Which "if" is the "else" on line 72 supposed to complete? Ken Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 6, 2008 Share Posted April 6, 2008 did you use the code under "Fix"??? i stated there would be errors please us this code: <?php require("connect.php"); $db = mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "<br /><br />Registering is disabled right now, please check back later."; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)){ die( "The username you entered encountered a problem.<br /><br />"); check($username);} if(!$password || !$password2 || !isset($password) || !isset($password2)||empty($password)||empty($password2)){ die ("The password field cannot be left empty!<br /><br />");} if(!$email||empty($email)||!isset($email){ die( "The email you entered encountered a problem.<br /><br />");} if($password != $password2){ die("The passwords you entered do not match.<br /><br />");} }else{ if(isset($password)||!empty($pasword)){ if(isset($username)||!empty($username)){ if(isset($email)||!empty($email)){ $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!';}}} } } ?> ALSO your structore is WRONG!!!!! it should be if elseif elseif elseif else or in your case if elseif else Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 6, 2008 Share Posted April 6, 2008 so i think i fixed the structure Try: <?php require("connect.php"); $db = mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "<br /><br />Registering is disabled right now, please check back later."; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } if(!isset($username) || empty($username)){ die( "The username you entered encountered a problem.<br /><br />"); check($username);} if(!$password || !$password2 || !isset($password) || !isset($password2)){ die ("The password field cannot be left empty!<br /><br />");} if(!$email||empty($email)||!isset($email){ die( "The email you entered encountered a problem.<br /><br />");} if($password != $password2){ die("The passwords you entered do not match.<br /><br />");} }else{ if(isset($password)||!empty($pasword)){ if(isset($username)|!empty($username)){ if(isset($email)|!empty($email)){ $query = "INSERT INTO users(username, password, email) VALUES('$username', '$password', '$email')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank you for registering with us " . $username . '! Enjoy your stay!';}}} } ?> Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 6, 2008 Author Share Posted April 6, 2008 Yes, I tried the one under fix. I just tried your latest one, the one where you say you fixed the structure. I still get the same error: Parse error: syntax error, unexpected '{' in /home/divnxn5/public_html/register2.php on line 56 I'm so lost o.O. Why would you take out the else after the form code? ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 6, 2008 Share Posted April 6, 2008 what happens if you take off the brackets around the if statements ??? Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 7, 2008 Author Share Posted April 7, 2008 It goes nutz o.o Parse error: syntax error, unexpected T_EXIT in /home/divnxn5/public_html/register2.php on line 57 D: Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 7, 2008 Share Posted April 7, 2008 change die to echo Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 7, 2008 Author Share Posted April 7, 2008 Still going nutz Parse error: syntax error, unexpected T_ECHO in /home/divnxn5/public_html/register2.php on line 57 My guess is the else before the if($_POST['register']) is suppose to close after the form. But I added a "{" to test it out and I still get same error. x.X Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 7, 2008 Share Posted April 7, 2008 most likely you will need ot rebuild the whole thing the structure is oddly out of whack. Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 9, 2008 Author Share Posted April 9, 2008 So I rewrote it: <?php require("includes/Connect.php"); mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "Registering is disabled right now, please check back later"; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)) { echo "The username you entered encountered a problem<br />"; check($username); } if(!$password || !$password2 || !isset($password) || !isset($password2) || empty($password) || empty($password2)) { echo "The password field(s) cannot be left empty.<br />"; } if(!$email || !isset($email) || empty($email)) { echo "The email you entered encountered a problem<br />"; } if($password != $password2) { echo "The passwords you entered do not match<br />"; } else { if(isset($username) && $password == $password2 && isset($email)) { $query = "INSERT INTO users(username, password, email, rank) VALUES('$username', '$password', '$email', '1')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank You for registering with us " . $username . '! Before you can login and start using the features of the site, please check the email you provided (' . $email . ') for a confirmation link.'; } } } } ?> But the logic problem is still there. If you enter nothing, it says username has a problem, but still adds you the the db. If you enter a username that is taken and no email, it adds you to the db. Some other situations as well. I tried to keep the structure you gave me, but I was getting so many errors and it wouldn't even show up. o.o D:! Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 9, 2008 Share Posted April 9, 2008 <?php if(isset($username) || $password=$password2 || isset($email)||!empty($email)||!empty($username)) {?> basically that tells it if its not empty and is set to add it else echo. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 9, 2008 Share Posted April 9, 2008 also you can add another if inside that if like <?php if(mysql_num_rows($username)<=0){ //insert }?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 10, 2008 Share Posted April 10, 2008 change: <?php if(mysql_num_rows($username)<=0){ //insert }?> to <?php if(mysql_num_rows($username)==0){ //insert }?> this will make sure it only inserts if there is no rows. or everything is not empty and is sumitted. Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 10, 2008 Author Share Posted April 10, 2008 <?php if(mysql_num_rows($username)==0){ //insert }?> This gives me back an error saying that mysql_num_rows isnt a valid MySql resource. D: Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 10, 2008 Share Posted April 10, 2008 my bad change $username to $result Quote Link to comment Share on other sites More sharing options...
Ne.OnZ Posted April 10, 2008 Author Share Posted April 10, 2008 It still goes through, if you enter a username that is taken, email left blank, some other situations. Code: <?php require("includes/Connect.php"); mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "Registering is disabled right now, please check back later"; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)) { echo "The username you entered encountered a problem<br />"; check($username); } if(!$password || !$password2 || !isset($password) || !isset($password2) || empty($password) || empty($password2)) { echo "The password field(s) cannot be left empty.<br />"; } if(!$email || !isset($email) || empty($email)) { echo "The email you entered encountered a problem<br />"; } if($password != $password2) { echo "The passwords you entered do not match<br />"; } else { if(isset($username) || $password == $password2|| isset($email) || !empty($email) || !empty($username)) { if(mysql_num_rows($result)==0) { $query = "INSERT INTO users(username, password, email, rank) VALUES('$username', '$password', '$email', '1')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank You for registering with us " . $username . '! Before you can login and start using the features of the site, please check the email you provided (' . $email . ') for a confirmation link.'; } } } } } ?> Also I still get the mysql error, so it's not checking if username is taken. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/divnxn5/public_html/register.php on line 76 o.o! Quote Link to comment Share on other sites More sharing options...
GameYin Posted April 10, 2008 Share Posted April 10, 2008 It still goes through, if you enter a username that is taken, email left blank, some other situations. Code: <?php require("includes/Connect.php"); mysql_select_db("divnx5_web"); $username = $_POST['user']; $password = sha1($_POST['pass']); $password2 = sha1($_POST['pass2']); $email = $_POST['email']; function error($result, $query) { if(!$result) { echo "Query Failed: $query<br />" . mysql_errno() . '<br />' . mysql_error(); } } function check($username) { $query = "SELECT `username` FROM `users` WHERE `username` = '$username'"; $result = mysql_query($query) or die("Problem with the query: $query<br />" . mysql_error()); if (mysql_num_rows($result) > 0) echo "The username " . $username . ' is already taken!<br /><br />'; } if(!$con) { echo "Registering is disabled right now, please check back later"; } else { if(!$_POST['register']) { echo "<br /><br />Use the following form to register a new account with us. <form action='register.php' method='post'><br /><br /> <font size='2'>Username:</font><br /> <input type='text' id='user' name='user' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Password:</font><br /> <input type='password' id='pass' name='pass' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>Confirm Password:</font><br /> <input type='password' id='pass2' name='pass2' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /> <font size='2'>E-mail Address:</font><br /> <input type='text' id='email' name='email' size='20' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br /> <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' /> </form>"; } else { if(!isset($username) || empty($username)) { echo "The username you entered encountered a problem<br />"; check($username); } if(!$password || !$password2 || !isset($password) || !isset($password2) || empty($password) || empty($password2)) { echo "The password field(s) cannot be left empty.<br />"; } if(!$email || !isset($email) || empty($email)) { echo "The email you entered encountered a problem<br />"; } if($password != $password2) { echo "The passwords you entered do not match<br />"; } else { if(isset($username) || $password == $password2|| isset($email) || !empty($email) || !empty($username)) { if(mysql_num_rows($result)==0) { $query = "INSERT INTO users(username, password, email, rank) VALUES('$username', '$password', '$email', '1')"; $result = mysql_query($query); error($result, $query); mysql_close($con); echo "Thank You for registering with us " . $username . '! Before you can login and start using the features of the site, please check the email you provided (' . $email . ') for a confirmation link.'; } } } } } ?> Also I still get the mysql error, so it's not checking if username is taken. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/divnxn5/public_html/register.php on line 76 If you are using that code, then you haven't defined $result and $query before using htem in a function Quote Link to comment 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.