Re: Debugging problems

From: Date: Tue, 22 May 2001 20:03:28 +0000
Subject: Re: Debugging problems
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53905@lists.php.net to get a copy of this message
best bet is to put some error checking in. function _check_db($query = '', $line = '') { if ( mysql_errno() ) { echo "Error: Problem with DataBase : {$GLOBALS['db_database']}<br>\n"; echo "Error: " . mysql_errno() . ':' . mysql_error() . "<br>\n"; echo "Query: $query<br>\n"; echo "Line : $line<br>\n"; exit(); } } after every mysql command put this. check_db($query, __LINE__); ie. <?php mysql_connect($db_hostname, $db_username, $db_password); check_db("connect: $db_hostname, $db_username, $db_password", __LINE__); ... mysql_db_query($db_database, $query); check_db($query, __LINE__); ?> this will help alot in finding any mysql errors. what was the command on line 27 ? email/news groups format posts, therefore line 27 for you may be line 33 when Im looking at it. -- Chris Lee lee@mediawaveonline.com ""Taline Makssabo"" <taline@prepresshelp.com> wrote in message news:MNEGLBDELEMBJDMIAFPCMEFICAAA.taline@prepresshelp.com... > I'm using this as a log on but it gives me this warning message: > > Warning: Supplied argument is not a valid MySQL resource > /httpd/html/php2/login.php on line 27 > > > <? ob_start() ?> > <?php > function access_denied() > > Header("WWW-Authenticate: Basic realm=\"$title\""); > Header("HTTP/1.0 401 Unauthorized"); > } > > function auth_headers($title) > > Header("WWW-Authenticate: Basic realm=\"$title\""); > Header("HTTP/1.0 401 Unauthorized"); > } > if(!isset($PHP_AUTH_USER)) > > auth_headers("Members Area"); > access_denied(); > exit; > } > else { > > $db_hostname = "localhost"; // database host, usually "localhost" > $db_username = "contact"; // username for the database (make sure it has > proper privledges) > $db_password = "cdi986"; // password that cooresponds to DB USERNAME > $db_database = "contact_informations"; // what database is your member info > stored in? > > $query = "SELECT username,password FROM contact_informations WHERE > username='$PHP_AUTH_USER' AND password='$PHP_AUTH_PW'"; > $link = mysql_connect($db_hostname, $db_username, $db_password) or > die("Unable to connect to database server"); > > if (mysql_num_rows(mysql_db_query($db_database, $query)) == 0) > > auth_headers("Members Area"); > access_denied(); > exit; > } > > mysql_close($link); > } > ?> > > > -- > 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 >

« previous php.general (#53905) next »