Page 1 of 1

if else

Posted: Thu Aug 07, 2003 12:48 am
by stockdalep
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.

Posted: Thu Aug 07, 2003 5:03 am
by patrikG
general advise: if your PHP version is 4.2+ use $_POST, not $HTTP_POST_VARS (see sticky in PHP Normal).
Instead of

Code: Select all

if ($number_of_rows <0)
use

Code: Select all

if (empty($number_of_rows))
Regarding your problem: Do you get an error message? If so, post it.

Posted: Thu Aug 07, 2003 1:31 pm
by patrikG
stockdalep,

I have read your thread. I replied with some general suggestions and a question.

PMing me the original post without looking into my question is
a) an insult to my ability to read
b) highly annoying
c) won't help you any further.

Goodbye, stockdalep.