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:
PHP Code:
//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?
|