Snooble Posted March 7, 2007 Share Posted March 7, 2007 <?php $check = "SELECT * FROM wmusers where username='".$_SESSION['usernamereg']."' LIMIT 1"; $checkresult = mysql_query($check); if(isset($_SESSION['usernamereg']) && strlen($_SESSION['usernamereg'] < "1")){ echo '<span class="registererror">(Empty) Username</span>'; } elseif(mysql_num_rows($checkresult) != 0){ echo '<span class="registererror">(Taken) Username</span>'; } else{ echo '<span class="register">Username</span>'; } ?> I need it to only display "(Taken) Username" when the username is taken. At the moment i get that all the time. I guess i need to add a new condition to the row check? Thank you, Snooble (Heres the checkregister.php ((The page this POST's to))) <?php include 'expire.php'; include 'sessionstartandsql.php'; $_SESSION['usernamereg'] = $_POST['username']; $_SESSION['passwordreg'] = $_POST['password']; $_SESSION['emailreg'] = $_POST['email']; if ($_POST['username'] == NULL){ header("Location: register.php");} if ($_POST['password'] == NULL){ header("Location: register.php");} if ($_POST['email'] == NULL){ header("Location: register.php");} if (!eregi('@', $_SESSION['emailreg'])) { header("Location: register.php");} $check = "SELECT * FROM wmusers where username='".$_POST['username']."' LIMIT 1"; $checkresult = mysql_query($check); if(mysql_num_rows($checkresult) != 0) header("Location: register.php"); $sql = "INSERT INTO wmusers VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0', '0', '0')"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); ?> Thanks Link to comment https://forums.phpfreaks.com/topic/41629-checking-mysql-num-rows/ Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 <?php $check = "SELECT * FROM wmusers where username='".$_POST['username']."' "; $checkresult = mysql_query($check); if(mysql_num_rows($checkresult) == 1){ echo "Sorry username tacken"; //add link to form to try agin exit; } ?> Link to comment https://forums.phpfreaks.com/topic/41629-checking-mysql-num-rows/#findComment-201700 Share on other sites More sharing options...
Snooble Posted March 7, 2007 Author Share Posted March 7, 2007 No, I need a more accurate condition. Your's is the same as mine. At the moment my statement: <?php elseif(mysql_num_rows($checkresult) != 0){ echo '<span class="registererror">(Taken) Username</span>'; } ?> Is always true. I need it to be more accurate so that if the user enters a username that's NOT in the database it executes the ELSE statement. Thanks for the responce nevertheless. Anyone? SNooble Link to comment https://forums.phpfreaks.com/topic/41629-checking-mysql-num-rows/#findComment-201715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.