if statement trouble.
Posted: Sat May 19, 2007 2:19 pm
Hi,
I am still adding (and having problems with...) a registration form for my site. The code below is the combined efforts of myself and a few others on here.
Basically, I have added and if statement to test if the 'loginid' has already been taken by another user.
Below is what I am having problems with. I am testing the form with new user information and the if statement returns true. I think it must be the query that is wrong. It shouldn't be returning true!
This is the whole script:
Thanks in advance
I am still adding (and having problems with...) a registration form for my site. The code below is the combined efforts of myself and a few others on here.
Basically, I have added and if statement to test if the 'loginid' has already been taken by another user.
Below is what I am having problems with. I am testing the form with new user information and the if statement returns true. I think it must be the query that is wrong. It shouldn't be returning true!
Code: Select all
$query = mysql_query ("SELECT loginid FROM members WHERE `loginid`='$loginid'");
if ($query){
echo "<h1>Sorry</h1><br>Thats login name has been taken.";
exit;
} Code: Select all
<?php
require 'main.inc.php';
$link = dbconnect();
$loginid = mysql_real_escape_string($_POST['loginid'], $link) or die(mysql_error());
$password = mysql_real_escape_string($_POST['password'], $link) or die(mysql_error());
$db = mysql_select_db('jobs4alltrades', $link);
$query = mysql_query ("SELECT loginid FROM members WHERE `loginid`='$loginid'");
if ($query){
echo "<h1>Sorry</h1><br>Thats login name has been taken.";
exit;
}
if(!$link){
echo "<h1>Sorry,</h1><br>We are having a few problems with our system. Please try again later. link";
exit;
}
else{
echo "<h1>Welcome</h1><br>Your details have been stored in our database. Use the the navigation bar at the top to look for jobs.";
}
if (!$db) die('could not select the database');
$insert = "INSERT INTO members (loginid, password, firstname, surname, email,
trade, address1, address2, address3, address4,
postzip, country, yearsexp, about)
VALUES ('".$_POST['loginid']."', '".$_POST['password']."', '".$_POST['firstname']."',
'".$_POST['surname']."', '".$_POST['email']."', '".$_POST['trade']."', '".$_POST['address1']."',
'".$_POST['address2']."', '".$_POST['address3']."','".$_POST['address4']."', '".$_POST['post']."',
'".$_POST['country']."','".$_POST['yearsexp']."','".$_POST['about']."')";
$result = mysql_query($insert, $link) or die("Query: $insert\n<br /.> MySQL Error: " . mysql_error());
exit;
?>