Re: Problem with Header()
| From: | Matt McClanahan | Date: | Thu, 10 Aug 2000 16:38:05 +0000 |
| Subject: | Re: Problem with Header() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11175@lists.php.net to get a copy of this message | ||
On Thu, 10 Aug 2000, Jay wrote:
> Thanks to all of those who have helped so far,
>
>
> I get still get this error:
>
> Warning: 0 is not a MySQL result index in (absolute path)/html.php3 on line
> 17
>
> Whenever someone accesses html.php3 alone, and not with html.php3?id=#
Makes sense.. You're using $id in your mysql_query. The query is failing,
but not reporting an error because you used @mysql_query. Since the query
fails, it returns 0 (false).
> All I want it to do is to check if it's empty and then redirect. Here is my
> code:
The if ($id) check is the right idea, but if it does trigger, it'll fail
because Header()'s need to be executed before any html is sent out. That
is, you need to remove the '<html>' on the first line. I'd move a check
on $id to the very top of the file, since you won't be able to do anything
if $id isn't set properly.
> <html>
> <?
> $server="localhost";
> $username="username";
> $password="pass";
> $database="database";
> $table="table";
>
> @mysql_connect($server, $username, $password) or die("Connection");
> @mysql_select_db($database) or die("Database");
> ?>
>
> <?
>
> $Result=@mysql_query("SELECT * FROM $table WHERE id=$id");
> while($row = @mysql_fetch_array($Result))
>
> if ($id) {
> header("Location: http://www.domain.com/");
> exit;
>
> } else {
>
> $title = $row["title"];
> echo "<head>
> <title>$title</title>
> <meta http-equiv='Content-Type' content='text/html;
> charset=iso-8859-1'>
> <style type='text/css'>
> <!--
> FORM { margin: 0px 0px}
> -->
> </style>
> </head>";
>
> }
>
> ?>
I assume you want to execute the else condition if $id is set, not if it
isn't. As it is now, the else condition will only run if $id is
false/unset. You probably want if (!$id)
HTH,
Matt