Re: Undefined variable
| From: | Dimitris Kossikidis | Date: | Fri, 19 Oct 2001 09:42:05 +0000 |
| Subject: | Re: Undefined variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71564@lists.php.net to get a copy of this message | ||
This should work ...
if ( IsSet($id) ) {
.....
sql statement
}else{
.....
}
----- Original Message -----
From: "Tshering Norbu" <norbu@druknet.net.bt>
To: <php-general@lists.php.net>
Sent: Friday, October 19, 2001 12:22 PM
Subject: [PHP] Undefined variable
> Dear list,
>
> I test the following script on local web server and it runs fine. But
when
> I upload the script to the real web server I get the following
> error/message, but the script works fine. Do you know why?
>
> Here is the error/message I get:
>
> Undefined variable : id in test.php on line 6
>
>
> And here is the script file (test.php):
>
> <html>
> <body>
> <?php
> $db = mysql_connect("localhost", "root", "root");
> mysql_select_db("penpal",$db);
> if ($id)
>
> $result = mysql_query("select * from penpal where id = $id",$db);
> $myrow = mysql_fetch_array($result);
> printf("<b>ID:</b> %s\n<br>", $myrow["id"]);
> printf("<b>Name:</b> %s\n<br>", $myrow["name"]);
> printf("<b>Age/Sex/Location:</b> %s\n<br>",
> $myrow["asl"]);
> printf("<b>Description:</b> %s\n<br>",
> $myrow["description"]);
> printf("<b>Email:</b> %s\n<br>", $myrow["email"]);
> } else {
> $result = mysql_query("select * from penpal order by id desc", $db);
> if ($myrow = mysql_fetch_array($result)) {
> do {
> printf("<a href = \"%s?id=%s\">%s %s</a><br>\n",
> $PHP_SELF,
$myrow["id"],
> $myrow["name"], $myrow["asl"]);
> } while ($myrow = mysql_fetch_array($result));
> } else {
> echo "Sorry, no records";
> }
> }
> ?>
> </body>
> </html>
>
>
>
> The id field in my table has the attribute: id tinyint (4)
>
> Thanks in advance
> NOBBY
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>