DeanWhitehouse Posted April 22, 2008 Share Posted April 22, 2008 $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name'")); i need this code to be this one , but work. $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name' AND WHERE user_email='$user_email'")); Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name'")); i need this code to be this one , but work. $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name' AND WHERE user_email='$user_email'")); $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_name='$user_name' AND user_email='$user_email'")); Don't say WHERE twice, and don't use ` on the column names. Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524400 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 this code was meant to check if the email is already in use but doesn't. why? <?php // Random Game Design: PHP Website Template // Version 1 // Copyright Dean Whitehouse, 2008 require_once 'db_connect.php'; // Connect to database mysql_connect($dbhost,$dbuser,$dbpass) or die('Could not connect: ' . mysql_error()); $user_name = $_POST["user_name"]; $user_password = $_POST["user_password"]; $user_password2 = $_POST["user_password2"]; $user_email = $_POST["user_email"]; $user_email2 = $_POST["user_email2"]; $ip = $_SERVER['REMOTE_ADDR']; $success = "/reg_success.php"; if ($_SESSION['is_valid'] == false) { //if(isset($_POST['agree'])){ if(isset($_POST['signup'])) { if ($user_name && $user_password && $user_password2 && $user_email && $user_email2) { $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_name='$user_name' AND user_email='$user_email'")); if ($user_check >= 1) { require_once 'register.php'; echo "Sorry, but the username or email you requested is already in use. Please enter a different username."; } elseif ($user_password == $user_password2 && $user_email == $user_email2) { $salt = substr($user_password, 0, 2); $userPswd = crypt($user_password, $salt); mysql_query("INSERT INTO `$user` (user_id, user_name, user_password, user_email, user_ip, userlevel) VALUES ('','$user_name','$userPswd','$user_email','$ip','2')") or die('Error ' . mysql_error()); echo "Succesfully Registered. You will recieve a confirmation email shortly."; header ("http://".$_SERVER[HTTP_HOST]."$success"); } else { require_once 'register.php'; echo "Either the passwords or emails you entered do not match. Please check these details and try again"; } } else { require_once 'register.php'; echo "Please fill in all of the required fields."; } } ?> <html> <table bgcolor='#999999' align='center' width="400px"> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <tr><td width="10px">Username: </td><td><input type='text' name='user_name' maxlength="20" width="400px" /><br /></td></tr> <tr><td width="10px">Maximum Length<br /> 20 characters.</td></tr> <tr><td width="10px">E-mail Address:</td> <td><input type='text' name='user_email' /><br /></td></tr> <tr><td width="10px">Confirm E-mail Address: </td><td><input type='text' name='user_email2' /><br /></td></tr> <tr><td width="10px">Password:</td><td> <input type='password' name='user_password' maxlength="30" /><br /></td></tr> <tr><td width="10px">Maximum Length<br /> 30 characters.</td></tr> <tr><td width="10px">Confirm Password:</td><td> <input type='password' name='user_password2' maxlength="30"/><br /></td></tr> <tr><td><input type='submit' value='Complete Registration' name='signup' /></td><td><input type="reset" value="Reset Fields" name="reset" /></td></tr> </form> </table> </html> <?php mysql_close(); } else { header("Location:http://".$_SERVER[HTTP_HOST]); } ?> also the header under the echo "Succesfully Registered. You will recieve a confirmation email shortly."; doesn't do anything Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524404 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Oh. Take off the WHERE user_name='$user_name' bit. Leave the email one though. Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524411 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 soz, and if there username is already taken. Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524416 Share on other sites More sharing options...
writer Posted April 22, 2008 Share Posted April 22, 2008 i need this code to be this one , but work. That cracked me up. Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524418 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Use OR instead of AND. Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524423 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 lol, yer, thanks(i thought that just before i read this) do u no how i can make a minimum input for the form, for the password area? Quote Link to comment https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524427 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.