rvdb86 Posted January 19, 2009 Share Posted January 19, 2009 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. ??? Quote Link to comment Share on other sites More sharing options...
namelessNN Posted January 19, 2009 Share Posted January 19, 2009 if there is ANY information being sent to the screen before that header redirect, it will not work. Quote Link to comment Share on other sites More sharing options...
iarp Posted January 19, 2009 Share Posted January 19, 2009 <?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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 19, 2009 Share Posted January 19, 2009 Why are you looping through the table instead of just using a WHERE clause on your query? Quote Link to comment Share on other sites More sharing options...
asmith Posted January 19, 2009 Share Posted January 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
iarp Posted January 19, 2009 Share Posted January 19, 2009 Well thats good to know, thanks. Quote Link to comment Share on other sites More sharing options...
rvdb86 Posted January 19, 2009 Author Share Posted January 19, 2009 hey everyone thanks for all the quick replies, i have managed to make it work now with your help. this is why this forum is so good! thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.