...

View Full Version : Redirect user if Value Not found



ajloun
01-19-2010, 03:26 AM
Hello

this is My code , i need to edit to redierect the user to main page when the ID not Found . in the Mysql

see if he type the url like : www.example.com/page?id=33

Now if the ID 33 not found to redierect the user to index.php


// connect here
$data = mysql_query("SELECT * FROM ".$DB->prefix("pages")." WHERE id='$id'") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
Echo "<b>page:</b> ".$info['page'] . "<br> ";
Echo "<b>url:</b> ".$info['url'] . "<br> ";
Echo "<b>name:</b> ".$info['name'] . "<br> ";
}

JAY6390
01-19-2010, 03:31 AM
$data = mysql_query("SELECT * FROM ".$DB->prefix("pages")." WHERE id='$id'") or die(mysql_error());
if(mysql_num_rows($result) == 0) {
header('Location: /index.php');
exit();
}
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
Echo "<b>page:</b> ".$info['page'] . "<br> ";
Echo "<b>url:</b> ".$info['url'] . "<br> ";
Echo "<b>name:</b> ".$info['name'] . "<br> ";
}

ajloun
01-19-2010, 03:54 AM
Thank you , working great ..


if(mysql_num_rows($result) == 0) {

to

if(mysql_num_rows($data) == 0) {

JAY6390
01-19-2010, 03:56 AM
Oops it's getting late. Glad you understood what I meant :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum