troubleshooting Question

PHP Redirect based on an IF statement not working?

Avatar of akashj
akashj asked on
PHP
42 Comments2 Solutions743 ViewsLast Modified:
Hi all,

I've got 2 sections of a php file
section 1. Has header information for the redirect
section 2. Has a SQL Statement that gets a COMPLETED or RUNNING status back

The header is :
<?php
$a = "http://www.google.com";  
$b = "http://www.yahoo.com";

if ($result = "COMPLETED1")
header("Location: $a");
else
header("Location: $b");
?>

Sql is:

<?php

$result=$sql_result;
// create connection
$connection = odbc_connect("server","user","password");

// test connection
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
// create SQL statement

$sql="
SELECT
[Status]
FROM
t_status.dbo.LoadStatus";

// prepare SQL statement
$sql_result = odbc_prepare($connection,$sql);

// execute SQL statement and get results
odbc_execute($sql_result);

// format result in HTML table
odbc_result_all($sql_result,"border=1");

// free resources and close connection
//odbc_free_result($sql_result);
//odbc_close($connection);

?>


Problem is, it doesn't seem to redirect.  It's always going to $a which is Google.
I changed the = to == which then sends it to Yahoo ($b) regardless of the result.

Can anyone help me out in this?  Not sure if the order is wrong...ie: is it trying to do the redirect before running the sql/getting the result?

Appreciate it.

Thanks
ASKER CERTIFIED SOLUTION
NeoAshura

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 42 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 42 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros