Start New Discussion Reply to this Discussion use of header location in while loop
<?php
session_start();
include "conn.php";
if (isset($_POST['submit']) && $_POST['billno']!='' )
{
$bill = $_POST['billno'];
$query = mysql_query("SELECT bill_no, tag_no FROM tbl_cargo_details WHERE bill_no='$bill' or tag_no ='$bill'")
or die(mysql_error());
while ($row = mysql_fetch_assoc($query))
{
if($bill == $row['bill_no'] || $bill == $row['tag_no'])
{
header("location:true.php?bill=$bill");
}
else
{
header("location:false.php?bill=$bill");
}
}
else
{
?>
i am not able to get the false page location when the condition fails. it only points to the first header location. i think first header is not passing the control when the condition is false. can any one help me out with this. Thanks..
10 Months Ago
Last Updated
Related Article: Issue in php header script
is a PHP discussion thread by raovinesh that has 37 replies and was last updated 6 months ago.
naresh.giri.146
Newbie Poster
1 post since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Hi,
I think that you dont need the while loop because an if is more than enough :)
Try this :
$query = mysql_query("SELECT bill_no, tag_no FROM tbl_cargo_details WHERE bill_no='$bill' or tag_no ='$bill'")
or die(mysql_error());
$num_rows = mysql_num_rows($query);
if($num_rows > 0){
// we are sure here that $bill == $row['bill_no'] or $bill == $row['tag_no']
header("location:true.php?bill=$bill");
}else{
// our mysql request has return 0 results
header("location:false.php?bill=$bill");
}
akmozo
Light Poster
48 posts since Jul 2012
Reputation Points: 5
Solved Threads: 9
Skill Endorsements: 0
Akmozo's should work, the problem is while ($row = mysql_fetch_assoc($query)) as when it finds nothing, it won't loop
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7
© 2013 DaniWeb® LLC
Page rendered in 0.0672 seconds
using 2.79MB