undefined variable when using if ($var) {}

From: Date: Mon, 25 Mar 2002 16:44:25 +0000
Subject: undefined variable when using if ($var) {}
Groups: php.general 
Request: Send a blank email to php-general+get-90057@lists.php.net to get a copy of this message
I'm rather new to PHP, so this should be fairly easy to answer. I checked the manual and FAQ already. I'm using the following code, and I get the following message if $id has nothing in the var (i have it set to a default of type int, not null in mysql). Is there a way around this or something I'm missing? Thanks :) -- code--- if ($id) { $result = mysql_query("SELECT * FROM entries WHERE id=$id",$db); $myrow = mysql_fetch_array($result); printf("<table border=1><tr>\n"); printf("<tr><td>%s</td></tr>", $myrow["title"]); printf("<tr><td>%s | ", $myrow["id"]); printf("%s</td></tr>", $myrow["posted"]); printf("<tr><td>%s\n</td></tr>", $myrow["post"]); printf("</table><tr>\n"); printf("<a href=\"$PHP_SELF\">all</a>"); } else { do { printf("%s <a href=\"%s?id=%s\">%s</a><br>\n", $myrow["id"], $PHP_SELF, $myrow["id"], $myrow["title"], $myrow["post"]); } while ($myrow = mysql_fetch_array($result)); } else { // no records to display echo "Sorry, no records were found!"; }

« previous php.general (#90057) next »