Hi guys,
I have a simple registration form and have had trouble getting it to check if the username is already taken in the database. This is what I have at the moment:
(the code i tried to use to make the check is about half way down)
<?php
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());;
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$uname = $_POST["uname"];
$pword = $_POST["pword"];
$email = $_POST["email"];
//above values are taken from form on previous page...
//first name, last name, username, password and email
$subject = "Thankyou for registering with Grafax!";
$from = "**myemail**";
$message = 'You have just registered the following details at Grafax.co.uk:<hr/>
<table bgcolor="#E0E0E0">
<strong>First Name: </strong>'. $fname .'<br/>
<strong>Last Name: </strong>'. $lname .'<br/>
<strong>Username: </strong>'. $uname .'<br/>
<strong>Password: </strong>'. $pword .'</table>
<hr/>
<h3><a href="#">Click here to login</a></h3>';
//this is where i tried to check the username against whats in the database.
//If $uname entered by user is different to the result from the mysql query
//then insert information. it didnt work.... :P
$dbunames = mysql_query("SELECT * FROM logins WHERE uname='$uname'");
if ($uname != $dbunames)
{
mysql_query("INSERT INTO ``.`` (`fname`, `lname`, `uname`, `pword`, `email`) VALUES ('$fname', '$lname', '$uname', '$pword', '$email')");
mail($email,$subject,$message,"From:$from\r\nReply-to: $from\r\nContent-type: text/html; charset=us-ascii");
echo "<h1>Successfully added: </h1><br><h3>fname:</h3>";
echo $fname;
echo "<br /><h3>lname:</h3>";
echo $lname;
echo "<br /><h3>uname:</h3>";
echo $uname;
echo "<br /><h3>pword:</h3>";
echo $pword;
echo "<hr>";
echo "<h1>Email sent to ". $email ."</h1>";
}
else
{
echo "Username taken.";
}
?>
<head>
<title>Insert Outcome</title>
</head>
Thanks all.
Max