Re: Undefined variable error ...

From: Date: Sat, 16 Sep 2000 01:50:57 +0000
Subject: Re: Undefined variable error ...
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-2927@lists.php.net to get a copy of this message
Sam, Thank-you - I took out the error reporting and the warning didn't display. The author of the article had me completely foxed. I thought that somehow PHP parsed the whole page and that the variables in the querystring were somehow created - for him, but not for me. Now I can proceed with fancying this up. Regards - Miles Thompson Sam Masiello wrote: > Since you have your error reporting set to 15, it will give you this warning > since you have not yet initialized the variable before you use it. It is > not an "error", rather a "warning." If you lower your error reporting > level, the warning will go away (although this doesn't mean that you will > miss possibly other more important warnings down the line :) ). > > Sam Masiello > System Analyst > Chek.Com > (716) 853-1362 x289 > smasiello@chekinc.com > > -----Original Message----- > From: Miles Thompson [mailto:milesthompson@sprint.ca] > Sent: Friday, September 15, 2000 12:39 PM > To: php-db > Subject: [PHP-DB] Undefined variable error ... > > 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 > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#2927) next »