I'm creating a script where users can create an account for a website. A section of the script is supposed to check if an account already exists for the user's email address before creating the account. This is what I have:
$db_name="test";
$table_name="accounts";
$connection = @mysql_connect("localhost","root","passw ord") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
//Check that the account does not already exsist
$sql = "SELECT email FROM $table_name WHERE email =\"$_POST[email]\"";
$result = @mysql_query($sql, $connection) or die(mysql_error());
if ($result != "$_POST[email]"){
$sql2 = "INSERT INTO $table_name (f_name, mi, l_name, email, password, s_address_1, s_address_2, s_city, s_state, s_zip) VALUES ('$_POST[f_name]', '$_POST[mi]', '$_POST[l_name]','$_POST[email]', password('$_POST[password]'), '$_POST[s_address_1]', '$_POST[s_address_2]', '$_POST[s_city]', '$_POST[s_state]', '$_POST[s_zip]')";
$result2 = @mysql_query($sql2, $connection) or die(mysql_Error());
echo "Account Created. You will receive a confirmation email shortly.";
}else{
echo "
$db_name="test";
$table_name="accounts";
$connection = @mysql_connect("localhost","root","passw
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
//Check that the account does not already exsist
$sql = "SELECT email FROM $table_name WHERE email =\"$_POST[email]\"";
$result = @mysql_query($sql, $connection) or die(mysql_error());
if ($result != "$_POST[email]"){
$sql2 = "INSERT INTO $table_name (f_name, mi, l_name, email, password, s_address_1, s_address_2, s_city, s_state, s_zip) VALUES ('$_POST[f_name]', '$_POST[mi]', '$_POST[l_name]','$_POST[email]', password('$_POST[password]'), '$_POST[s_address_1]', '$_POST[s_address_2]', '$_POST[s_city]', '$_POST[s_state]', '$_POST[s_zip]')";
$result2 = @mysql_query($sql2, $connection) or die(mysql_Error());
echo "Account Created. You will receive a confirmation email shortly.";
}else{
echo "
ERROR: An account already exists for this email address.
Click here if you forgot your password.
";
}
The result returned is always "resource id #3", rather than the actual email address. I did some research and read that I should use the mysql_fetch_array() function but I'm not sure how to use it in this case. Help?
