Reputation: 163
working on a small project and having a small problem. i am querying mysql, i am able to get the array and everything works well but i am adding a additional condition if returns 0 or id does not match the query then redirect.
This is what i have so far.
$q = "SELECT TEST.*,
EMPLOYEE.EMP_ID
FROM TEST
LEFT JOIN EMPLOYEE ON TEST.EMP_ID = EMPLOYEE.EMP_ID
WHERE ITEM_ID=".$db->qstr($item_id);
if(!$item_id = $db->execute($q)){
force_page('system', 'Nothing found');
exit;
} else {
$view = $item_id->GetArray();
}
return $view;
}
so the above returns the array, query grabs $item_id from the url so it could be anything. i would like to check if that id exists if not then force the page as shown in the above. any suggestion on what i am doing wrong?
Upvotes: 0
Views: 372
Reputation: 5712
If you want to redirect you can use header
function
header("Location: put_your_url_here");
e.g.
header('Location: /mypage.php');
Upvotes: 1
Reputation: 1996
I don't think there is any function like force_page();
in php
You need to redirect like header("Location: Your_url");
And If you have function force_page();
please post code of that.
Upvotes: 0
Reputation: 11859
header("Location: Your_url");
will help you to redirect based on your condition.but make sure that you have not echoed any thing before the header otherwise it won't redirect.
Upvotes: 0
Reputation: 1840
There is no function such as force_page
in PHP. You can use header
to redirect user to another page. Modify your if
condition as
if(!$item_id = $db->execute($q)){
header("Location: url_to_redict");
die();
}
Upvotes: 0