This is a section from a working logon script. We want to redirect to different URL’s based on the text in an existing database field. Don’t get any error msgs, jus blank page. Thanks for helping a rank amateur!
[php]
<?php
session_start();
if(!session_is_registered(email)){
header("location:johnlogin1.php");
}
if ($user->logged_in)
{
$query = "SELECT * FROM orders";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['description'];
}
if($description=='monkey') // condition for one keyword
{
$url='http://www.monkey.com'; // url or page to redirect on keyword
header('Location:$url');
}
if($description=='banana') // condition for other keyword
{
$url='www.banana.com';
header('Location:$url');
}
?>
Revised code to this version and checked for errors = none. Still no redirect - blank page…
[php]
<?php
include 'johnlogin0.php';
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
{
$sql="SELECT * FROM $tbl_name WHERE description='description'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['description'];
}
if(description=='monkey') // condition for one keyword
{
//$url='www.monkey.com'; // url or page to redirect on keyword
header('Location:$url');
}
if(description=='banana') // condition for other keyword
{
//$url='www.banana.com';
header('Location:$url');
}
?>
Script updated as below. No errors reported. No echo… Still blank page on execute.
[php]
<?php
error_reporting(E_ALL);
echo ini_get('display_errors');
include 'johnlogin0.php';
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
{
$sql="SELECT * FROM $tbl_name WHERE description='description'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['description'];
}
if(description=='monkey') // condition for one keyword
{
//$url='www.monkey.com'; // url or page to redirect on keyword
header('Location:$url');
}
if(description=='banana') // condition for other keyword
{
//$url='www.banana.com';
header('Location:$url');
}
?>
Example posted in Item #4 above incorrect - here’s the right example - still displays blank page only an no errors.
[php]
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'johnlogin0.php';
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
{
$sql="SELECT * FROM $tbl_name WHERE description='description'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['description'];
}
if(description=='monkey') // condition for one keyword
{
$url='www.monkey.com'; // url or page to redirect on keyword
header('Location:$url');
}
if(description=='banana') // condition for other keyword
{
$url='www.banana.com';
header('Location:$url');
}
?>
Other suggestions included, as shown below. No Joy.
[php]
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'johnlogin0.php';
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");
{
$sql="SELECT * FROM $tbl_name WHERE description='description'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['description'];
}
if($row['description']=='monkey') // condition for one keyword
{
$url='http://www.monkey.com'; // url or page to redirect on keyword
header('Location:$url');
}
if($row['description']=='banana') // condition for other keyword
{
$url='http://www.banana.com';
header('Location:$url');
}
?>
Sorry I cannot offer much help but maybe I can suggest watching this tutorial on youtube. I cannot post urls so search for phpacademy redirect_to and it is the first tutorial from ‘the newboston’.