include ("server details");
$tbl_name="login";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['username2'];
$myemail=$_POST['email'];
$mypassword=$_POST['password1'];
$sql="SELECT * FROM $tbl_name WERE username='$myusername'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
echo "This username has already been taken please register with a different one.";
header("location:registermain.php");
}
else {
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myemail = stripslashes($myemail);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$myemail = mysql_real_escape_string($myemail);
$sql = "INSERT INTO $tbl_name (username, email, password) VALUES
('$myusername', '$myemail', '$mypassword')";
$result = mysql_query($sql);
if($sql==true){
echo "Thank you for registering";
}
else {
echo "<p>Please try again there seems to be a problem if the problem persists please contact admin.</p>";
}}
what I'm after here is for the code above to only submit the details from the previous form if the username doesn't exist in the database. The code just submits them anyway.
$tbl_name="login";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['username2'];
$myemail=$_POST['email'];
$mypassword=$_POST['password1'];
$sql="SELECT * FROM $tbl_name WERE username='$myusername'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
echo "This username has already been taken please register with a different one.";
header("location:registermain.php");
}
else {
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myemail = stripslashes($myemail);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$myemail = mysql_real_escape_string($myemail);
$sql = "INSERT INTO $tbl_name (username, email, password) VALUES
('$myusername', '$myemail', '$mypassword')";
$result = mysql_query($sql);
if($sql==true){
echo "Thank you for registering";
}
else {
echo "<p>Please try again there seems to be a problem if the problem persists please contact admin.</p>";
}}
what I'm after here is for the code above to only submit the details from the previous form if the username doesn't exist in the database. The code just submits them anyway.