Undefined variable error ...

From: Date: Fri, 15 Sep 2000 16:38:36 +0000
Subject: Undefined variable error ...
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-2915@lists.php.net to get a copy of this message
The following code consistently generates a warning about an undefined variable cAdminID, yet works aside from that. Hereis the warning: "Warning: Undefined variable: cAdminId in /usr/local/apache/htdocs/auction/zztest2.php on line 28" and it occurs on the line "if ($cAdminId)". The code has been taken from Graeme Merrall's PHP/MySQL Tutorial at Webmonkey. My code follows, the error occurs whether I use "auth.inc" or not: ****START*** <? /* Default administrative php page for Auction site. Always attempts connection to database and authorization. Developed by: CQA Consulting Group 33 Alderney Dr., Enfield, NS Canada B2T 1J8 Phone: (902 ) 883-1010 Fax: (902) 883-8586 */ include('auth.inc'); ?> We're in! <? // We're going to try continue with the connection established in auth.inc // if it doesn't work, then re-establish connnection and database error_reporting( 15 ); $db = mysql_pconnect("localhost","root") or die("Unable to connect to SQL server"); mysql_select_db("auction", $db) or die("Unable to select database"); if($cAdminId) { echo "This is the Admin ID ", $cAdminId, "<br>"; $sql = "select * from admin where cAdminId = '$cAdminId'"; $result = mysql_query( $sql ); $myrow = mysql_fetch_array( $result ); ?> <form method = "post" action = "<? echo $PHP_SELF ?>"> <!-- <input type = hidden name = "cAdminId2" value = <? echo $myrow["cAdminId"] ?>"> --> ID: <input type = "text" name = "cAdminId" value = <? echo $myrow["cAdminId"] ?>> <br> First Name <input type = "text" name = "cFirstName" value = <? echo $myrow["cFirstName"] ?>> <br> Last Name <input type = "text" name = "cLastName" value = <? echo$myrow["cLastName"] ?>> <br> Password: <input type = "text" name = "password" value = <? echo $myrow["cPassword"] ?>> <br> <input type ="Submit" name ="submit" value = "Enter Information"> </form> <? } else { // display list of administrators $result = mysql_query( "select * from admin", $db ); echo $result, "<br>"; if ( $myrow = mysql_fetch_array( $result )) { do { printf("<a href=\"%s?cAdminId=%s\">%s %s %s</a><br>\n", $PHP_SELF, $myrow["cAdminId"], $myrow["cFirstName"], $myrow["cLastName"], $myrow["cPassword"]); } while( $myrow = mysql_fetch_array( $result )); } else { echo "Sorry, no records found."; } } ?> *****END**** This is the structure of the admin table in the auction database: create table admin ( cFirstName varchar(20), cLastName varchar(20), cAdminId char(10) not null , cPassword char(10) , lAuthBids tinyint , lAuthUsers tinyint , nAdminKey integer unsigned not null auto_increment primary key, index (cAdminID) ) ; If anyone can point out what is probably a ridiculous error I would greatly appreciate it. I've checked for each instance of "cAdm", read the code aloud, tried explaining what is going on to my wife (which usually works), and so forth. As near I can tell PHP isn't doing it's magical variable creation in the printf() which generates the link and querystring. Thanks in advance, Miles Thompson

« previous php.db (#2915) next »