Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using header() to redirect
Old 09-22-2008, 08:46 PM Using header() to redirect
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
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?
__________________

Please login or register to view this content. Registration is FREE
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
 
Register now for full access!
Old 09-22-2008, 10:40 PM Re: Using header() to redirect
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
Problem solved and had nothing at all to do with the header() function. It was my query! Funny how you can't satisfy an "if" when you never satisfy the conditions!
__________________

Please login or register to view this content. Registration is FREE
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
Old 09-23-2008, 03:31 AM Re: Using header() to redirect
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Again you select * just to get the number of records. You should select count(*) instead.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Using header() to redirect
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.80565 seconds with 12 queries