Forum Moderators: coopster
If the call to the page has no $num key I send them to the front of the site with a redirect, now after doing site: in google I noticed it has a page that no longer has content from the db so I tried another header location but got the "headers already sent warning" heres my code
$sql = "select * from db where num ='$num'";
if ($_REQUEST[num] == '' ¦¦ mysql_num_rows($sql < 1))
{
header("Location: http://www.example.com/");
exit;
}
I now get the following message if a page HAS content and is displayed
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
Is the above correct? what do I need to do about the Warning?
Thanks in advance
EDIT sorry mod's I should have posted this in the database forum, please move if you feel fit
$sql = "select * from db where num ='$num'";
$result = mysql_query($sql);
$no_result = mysql_num_rows($result);
if ($_REQUEST[num] == '' ¦¦ $no_result < 1)
{
header("Location: http://www.example.com/");
exit;
}
Does the above look ok
[edited by: eelixduppy at 4:36 pm (utc) on May 17, 2007]
[edit reason] delinked [/edit]
There is another problem, however, that may not actually be a problem but I don't know what you have before this code. Just note that having
$num in the query, if the variable's value is defined by the user (or can be), can present a security issue through SQL Injection. Read up on mysql_real_escape_string [php.net] for more information on what can be done to prevent this. >>I should have posted this in the database forum
No worries. This is a PHP related problem and should be in here :)