开发者

Re-direct query not working

The code below is supposed to redirect the user to the index file if the user ($uid) has submitted an entry in the last hour. It's not working.

Any idea why not?

Thanks in advance,

John

$quer开发者_高级运维yuidcount = "select loginid from submission where datesubmitted > (NOW() - INTERVAL 1 hours) AND loginid = '$uid'"; 
$uidresult = mysql_query($queryuidcount);

if (mysql_num_rows($uidresult) >= 1)
{

   session_write_close();
   header("Location:http://www.domain.com/sample/index.php");
   exit;

}


First of all, there should be a space between Location: and http://someurl, otherwise it's not a correctly formed HTTP header (some browsers can cope, some choke on it):

Location: http://someurl

Second, are you getting a "headers already sent" warning? That would mean you already started output before this line (e.g. whitespace at file beginning, UTF BOM marks, etc.)


Looks like you have forgot to put session_start() on top of your script since you are using a sessio related function below. Also, no need to specify whole domain path, just the file name should be fine:

header("Location: index.php");

If there is any error, you can know about it by putting these lines on top of your script:

ini_set('display_errors', true);
error_reporting(E_ALL);

Also make sure that some records are returned:

if (mysql_num_rows($uidresult) >= 1)
{
   exit('found rows !!');
}


Does the code even reach the code inside the if-statement? try a var_dump("foo"); there, because I reckon the header looks good. It could be that the exit; is interfering with the redirect though. Good luck!


The SQL code doesn't seem correct. Change the hours to hour instead.

(NOW() - INTERVAL 1 hour)

Perhaps you could you use TIMEDIFF instead?

mysql> select TIMEDIFF('2010-07-07 09:38:28',NOW()); 
+---------------------------------------+
| TIMEDIFF('2010-07-07 09:38:28',NOW()) |
+---------------------------------------+
| -01:03:38                             |
+---------------------------------------+
1 row in set (0.00 sec)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜