You are here: Re: Troublesome Code. « PHP « IT news, forums, messages
Re: Troublesome Code.

Posted by M. Sokolewicz on 01/31/05 15:09

Chris Knipe wrote:
> Lo everyone,
>
> Can someone please perhaps just indicate to me what is wrong with the
> below code? I am getting SQL Result errors, but all the queries
> executes successfully.
>
> Errors in browser:
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
> resource in
> /usr/local/www/v-webs/O/OUR001/management.ournet.co.za/htdocs/dialupadmin/index.php
> on line 11
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /usr/local/www/v-webs/O/OUR001/management.ournet.co.za/htdocs/dialupadmin/index.php:11)
> in
> /usr/local/www/v-webs/O/OUR001/management.ournet.co.za/htdocs/dialupadmin/index.php
> on line 28
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /usr/local/www/v-webs/O/OUR001/management.ournet.co.za/htdocs/dialupadmin/index.php:11)
> in
> /usr/local/www/v-webs/O/OUR001/management.ournet.co.za/htdocs/dialupadmin/index.php
> on line 29
>
> Authentication Required.
>
>
>
> Below is the code with explanations...
>
> <?
> if (!isset($_SERVER['PHP_AUTH_USER'])) {
> header('WWW-Authenticate: Basic realm="Cenergy Dialup Admin"');
> header('HTTP/1.0 401 Unauthorized');
> WritePageStart("Error - Authentication Required", "", "");
> echo "<p>Authentication Required.</p>";
> WritePageEnd();
> exit;
> } else {
> $SQL = mysql_query("SELECT RadiusAdmin.isWIFI AS isWIFI,
> RadiusAdmin.isPPTP AS isPPTP, RadiusAdmin.isDIAL AS isDIAL,
> RadiusAdmin.MinTokens AS MinTokens, RadiusAdmin.TokenCost AS TokenCost,
> RadiusAdmin.CustID AS CustID, RadiusAdmin.Realm AS Realm,
> SMTPZones.EntryID AS ZoneID, RadiusAdmin.Username AS AccountName,
> RadiusAdmin.Tokens AS Tokens, RadiusAdmin.Balance AS Balance FROM
> RadiusAdmin LEFT JOIN SMTPZones ON RadiusAdmin.Realm=SMTPZones.Zonename
> WHERE RadiusAdmin.Username='" . $_SERVER['PHP_AUTH_USER'] . "' AND
> RadiusAdmin.Password=MD5('" . $_SERVER['PHP_AUTH_PW'] . "') LIMIT 1");
>
> ^^^ Line 10. Query does execute successfully, and returns 1 Row.
No it doesn't, it returns FALSE (because there was an error). Use
mysql_error() to find out the problem.
>
>
> if (mysql_num_rows($SQL) == 1) {
> ^^^^^^ Line 11 (I also tried == "1" to no avail).
It gets $SQL=false since mysql_query() returned false. Use mysql_error()
to find out the problem.
>
> while ($Data = mysql_fetch_array($SQL)) {
> $_SESSION['Username'] = $_SERVER['PHP_AUTH_USER'];
> $_SESSION['CustID'] = $Data['CustID'];
> $_SESSION['ZoneID'] = $Data['ZoneID'];
> $_SESSION['Realm'] = $Data['Realm'];
> $_SESSION['AccountName'] = $Data['AccountName'];
> $_SESSION['Tokens'] = $Data['Tokens'];
> $_SESSION['TokenCost'] = $Data['TokenCost'];
> $_SESSION['MinTokens'] = $Data['MinTokens'];
> $_SESSION['isDIAL'] = $Data['isDIAL'];
> $_SESSION['isPPTP'] = $Data['isPPTP'];
> $_SESSION['isWIFI'] = $Data['isWIFI'];
> $_SESSION['Balance'] = $Data['Balance'];
> }
> $SQL = mysql_query("UPDATE RadiusAdmin SET LastAccess=NOW() WHERE
> Username='" . $_SERVER['PHP_AUTH_USER'] . "'");
> } else {
> header('WWW-Authenticate: Basic realm="Cenergy Dialup Admin"');
> header('HTTP/1.0 401 Unauthorized');
> ^^^^^^^^ This generates the last two errors - hence, my problem is at
> line 10 & 11?
> WritePageStart("Error", "", "");
> echo "<p>Authentication Required.</p>";
> WritePageEnd();
> exit;
> }
> }
>
>
> Thanks,
> Chris.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация