I have a databse which has to check for duplicates in the password field before entering the total amount of data, if I put in a duplicate it tell s me how many rows it has found but I cannot seem to get the if else statement to work.
<?php
session_start();
$forname = $HTTP_POST_VARS['forname'];
$surname = $HTTP_POST_VARS['surname'];
$email = $HTTP_POST_VARS['email'];
$mobile = $HTTP_POST_VARS['mobile'];
$address = $HTTP_POST_VARS['address'];
$address2 = $HTTP_POST_VARS['address2'];
$postcode = $HTTP_POST_VARS['homepostcode'];
$telephone = $HTTP_POST_VARS['hometel'];
$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];
$confirmpassword = $HTTP_POST_VARS['confirmpassword'];
$selectarea = $HTTP_POST_VARS['selectarea'];
$db_name = "central";
$table_name = "register";
$connection = @mysql_connect("*********","centralexpress","crownhill")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
mysql_select_db("central");
$query = "SELECT * FROM $table_name WHERE ".'password'." like '%".$password."%'";
// execute the SQL statement
$result1 = mysql_query($query, $connection) or die(mysql_error());
//get the number of rows in the result set
$number_of_rows = mysql_num_rows($result1) or die(mysql_error());
if ($number_of_rows <0)
{
$sql="INSERT INTO $table_name (forname,surname,email,mobile,address,address2,postcode,telephone,username,
password,confirmpassword,collectionarea) VALUES ('$forname',
'$surname', '$email', '$mobile','$address',
'$address2', '$postcode', '$telephone', '$username
', '$password', '$confirmpassword', '$selectarea')";
$result = @mysql_query($sql,$connection) or die(mysql_error());
echo"Registered!";
}
else
{
echo "password Exists choose another";
echo "$number_of_rows";
}
?>
Thanks for any help ALAN.
if else
Moderator: General Moderators
general advise: if your PHP version is 4.2+ use $_POST, not $HTTP_POST_VARS (see sticky in PHP Normal).
Instead of
use
Regarding your problem: Do you get an error message? If so, post it.
Instead of
Code: Select all
if ($number_of_rows <0)Code: Select all
if (empty($number_of_rows))