Jump to content

[SOLVED] Check database if record exsists


rvdb86

Recommended Posts

hey guys i want to check my database to see if an email address already exsists, if it does i want the user to be redirected, if not the code just continues. this is my code:

 

$query_check = "SELECT * FROM tbl_customers";
                    $result_check = mysql_query($query_check)
                        or die ("Couldn't execute query");
                    while ($row_check = mysql_fetch_array($result_check))
                    {
                        extract($row_check);
					if($customer_email == $_POST['email']){
					header("location:register_site.php?er=yesh");
					}
				}

 

for some reason it does not redirect them, I hope some one can tell me what i am doing wrong. ???

Link to comment
Share on other sites

<?php
$query_check = "SELECT * FROM tbl_customers";
$result_check = mysql_query($query_check) or die ("Couldn't execute query");
while ($row_check = mysql_fetch_array($result_check)) {
extract($row_check);
if($customer_email == $_POST['email']){
    $url = "register_site.php?er=yesh");
    header("Location: $url");
}
}
?>

 

Now i've never heard of extract so i dont know if it won't redirect because of a bad value there.

Link to comment
Share on other sites

Try this one :

 

<?php
$query_check = "SELECT * FROM tbl_customers WHERE customer_email ='". $_POST['email'] "'";
                    $result_check = mysql_query($query_check)
                 if (mysql_num_rows($result_check) != 0)
                  header("location:register_site.php?er=yesh");
                  
?>

             

 

remember to validate email address, before using it straight in the query.

 

@iarp

extract makes the keys of an array the variable name, and values of that array, the variable value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.