matts_sandbox Posted April 15, 2006 Share Posted April 15, 2006 The following PHP code used to work perfectly:/*verify registration*/$sql_user_check = "select * from firstmysqltable where email='$email'";$result_name_check = mysql_query($sql_user_check); $usersfound = mysql_num_rows($result_name_check); // if user not found, note that and end if ($usersfound < 1) header("Location: [a href=\"http://www.site.com/stopit.html");\" target=\"_blank\"]http://www.site.com/stopit.html");[/a]// if user does exist, continue with processing elseheader("Location: [a href=\"http://www.site.com/goahead.html");\" target=\"_blank\"]http://www.site.com/goahead.html");[/a]Then I attempted to “enhance” the process:/*verify registration*/$sql_user_check = "select * from mysecondtable where email='$email' and secondcolumn='on'";$result_name_check = mysql_query($sql_user_check); $usersfound = mysql_num_rows($result_name_check); if ($usersfound < 1) header("Location: [a href=\"http://www.site.com/stopit.html");\" target=\"_blank\"]http://www.site.com/stopit.html");[/a]// if user does exist, continue with processing elseheader("Location: [a href=\"http://www.site.com/goahead.html");\" target=\"_blank\"]http://www.site.com/goahead.html");[/a]Now, everything goes to stopit.html. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/7494-conditional-redirection/ Share on other sites More sharing options...
toplay Posted April 15, 2006 Share Posted April 15, 2006 Always check for any MySQL errors before executing any subsequent MySQL commands. Check that the query works before running the number of rows function. You may have a syntax error in your SQL. Do something like this to help yourself debug the problem:[code]// Add to make sure you see PHP errors/warnings/noticesini_set('display_errors', '1');error_reporting(E_ALL);/*verify registration*/$sql_user_check = "select * from mysecondtable where email='$email' and secondcolumn='on'";$result_name_check = mysql_query($sql_user_check);if (!$result_name_check) { // Add to debug echo "SQL: $sql_user_check Error: ", mysql_error(); exit; // Stop script to fix error}$usersfound = mysql_num_rows($result_name_check);if ($usersfound < 1)header("Location: http://www.site.com/stopit.html");// if user does exist, continue with processingelseheader("Location: http://www.site.com/goahead.html");exit;[/code]Please note that the header() with location command does not redirect right there and then when it's executed. It actually redirects when your script ends or an exit/die is reached. So, to ensure no logic flow problems in your script, you should have an exit right after every header() with location to force redirection to occur immediately (if that's what you want/expect). Quote Link to comment https://forums.phpfreaks.com/topic/7494-conditional-redirection/#findComment-27353 Share on other sites More sharing options...
matts_sandbox Posted April 16, 2006 Author Share Posted April 16, 2006 I very, very much appreciate the reply, but it still doesn't work. I've checked, and the MySQL works fine. I think it's something I don't understand about the attempted redirection. In other words:$usersfound = 1 BUT in all instances, the redirection is to stopit.htmlHelp, I've been trying to fix this for something like 3 hours, and I'm gonna bust! Quote Link to comment https://forums.phpfreaks.com/topic/7494-conditional-redirection/#findComment-27365 Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 Well, it's not finding a match in the table with whatever the value of $email is (and the secondcolumn having to be set to "on").Where is $email coming from or being assigned?if it's passed from a form through GET method use $_GET['email'] and if it's through POST use $_POST['email']. Example:[code]...$email = ('get' == strtolower($_SERVER['REQUEST_METHOD'])) ? $_GET['email'] : $_POST['email'];$email = get_magic_quotes_gpc() ? $email : addslashes($email);$sql_user_check = "select * from `mysecondtable` where `email` = '$email' and `secondcolumn` = 'on'";...[/code]Start putting displays (echo/print) at strategic places within your code to help yourself debug this.Try the SQL query in the mysql command line, phpmyadmin or similar tool to see what you get.If this doesn't help you, then you need to provide more info and the complete exact code you're using. Quote Link to comment https://forums.phpfreaks.com/topic/7494-conditional-redirection/#findComment-27368 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.