Jump to content

Recommended Posts

$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'"));

Link to comment
https://forums.phpfreaks.com/topic/102411-mysql-help/
Share on other sites

$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.

 

Link to comment
https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524400
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/102411-mysql-help/#findComment-524404
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.