Help - Search - Members - Calendar
Full Version: Using header() to redirect
Weborum Webmaster Forum > Web Page Design > PHP
susa
I am writing a script to update a database. Part of the update checks for a duplicate stock number and I want to redirect back to the input form if there is a duplicate. If there is no duplicate, send the user off to another script to finish up the process.

Here is the code I am using:

QUOTE
//sql check routine
//check for duplicates in database by stock number
session_start();
unset($_SESSION[error]);
require_once("database.php");
$stock_num=$_POST[stock_num];
$_SESSION[stock_num]=$stock_num;
$sql="SELECT * FROM vehicles where stock_num = '$stock_num'";
$result=mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result)!=0){
//There is a duplicate stock number so go back to form with an error
$_SESSION[error]="There is a duplicate";
}
if ($_SESSION[error]){
header("Location: newad.php");
}

else {
header("Location: preview_text.php");
}


No matter what the results of my query, the next script called is always preview_text.php. What am I doing wrong?

_____________________________
baby gift Audi A4 Ignition Coils
Joe
Why don't you put the header call for the duplicate inside the first IF statement where you set the SESSION?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.