I have a problem with checking if the username exist. It works if it does exist. But if the username doesn’t exist it just send me to an empy page. It seems that it doesn’t go to the next statement.
Here the code
<?php
if($_POST[username] && $_POST[email] && isset($_POST[password]) && isset($_POST[password2]) && $_POST[password] == $_POST[password2])
{
include ('*********'); /my connection to the database
$username = $_POST[username];
//check with the registred members
$query2 = "SELECT * FROM registredMembers WHERE username='$username'";
$result2 = mysql_query($query2, $conn) or die(mysql_error());
$existing_users = mysql_num_rows($result2) or die(mysql_error());
// check with the temporarly members, waiting to activate account
$query3 = "SELECT * FROM tempMembers WHERE username='$username'";
$result3 = mysql_query($query3, $conn) or die(mysql_error());
$existing_users2 = mysql_num_rows($result3) or die(mysql_error());
if($existing_users != 0 && $existing_users2 != 0)
{
echo "<div id='msg'>Användarnamnet är upptaget</div>";
}
else
{
$confirmCode = md5(uniqid(rand()));
$query = "INSERT INTO tempMembers VALUES ('$confirmCode', '$_POST[username]', '$_POST[email]', '$_POST[password]')";
$result = mysql_query($query, $conn) or die(mysql_error());
if($result)
{
$to = $_POST[email];
$subject = utf8_decode("Här är din bekräftelselänk");
$header = utf8_decode("Från Adib Haider (PHP-Projekt)");
$message = "Din bekräftelselänk \r\n";
$message.= "Klicka på länken för att aktivera ditt konto \r\n";
$message.= "http://labb.vgy.se/~adibbinhar/blogg/confirmation.php?passkey=$confirmCode";
$sentmail = mail($to, $subject, utf8_decode($message), $header);
if($sentmail)
echo "<div id='msg'>Aktiveringsmailet har skickat till din e-postadress</div>";
else
echo "<div id='msg'>Aktiveringsmailet skickades inte</div>";
}
else
echo "<div id='msg'>Testa igen</div>";
}
}
else
echo "<div id='msg'>Prova igen</div>";
the text is on swedish hope you can live with that 😛
/I went through your code and added a little protection from injections as well as hopefully fixing your problem.
Like Joachim said, when the mysql_num_rows didn’t return anything, you die() the script.
This is the code I whipped together, you need to check the tables are correct and like, as this was a real quick run through: