[PHP] Debugging problems

2001-05-22 Thread Taline Makssabo

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Debugging problems

2001-05-22 Thread Chris Lee

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: $querybr\n;
   echo Line : $linebr\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
  [EMAIL PROTECTED]



Taline Makssabo [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] debugging problems

2001-05-18 Thread Taline Makssabo

This is a program i wrote to get some information at keep track with some
stats. I am very new at this so bare with meI keep on getting this
Warning:

Warning: Supplied argument is not a valid MySQL result resource in
/home/virtual/ppcu/home/httpd/html/php2/stat.php on line 13

Warning: Supplied argument is not a valid MySQL-Link resource in
/home/virtual/ppcu/home/httpd/html/php2/stat.php on line 17

Whats wrong Is it my code? Please help.

?

global $dblink,$PHP_SELF;
$ip = getenv(REMOTE_ADDR);
$host = getenv(HTTP_HOST);
$browser = getenv(HTTP_USER_AGENT);
$referer = getenv(HTTP_REFERER);
$sql = SELECT ipaddress FROM stat WHERE ipaddress = '$ip';
$connection = @mysql_connect(localhost, username, password) or
die(Couldn't connect.);
$db_name = contact;
$table_name = stat;
$result = @mysql_query($sql, $dblink);
$num = mysql_num_rows($result);
if( $num == 0 )
{
$sql =INSERT INTO stat(ipaddress,host,browser,referer,filename)
VALUES('$ip', '$host', '$browser', '$referer','$PHP_SELF');
$result=mysql_query($sql,$dblink);
$sql1=INSERT INTO hits(ipaddress,count) VALUES('$ip',1);
$result1=@mysql_query($sql1,$dblink);
$text=you had a new visitor from IP: $ip, Host: $host Browser:
$browser Referer: $referer;
 if ($result)
{
mail([EMAIL PROTECTED], You had a new visitor,$text, FROM:
[EMAIL PROTECTED]);
}
}else{
$sql = UPDATE hits SET count = count + 1 where ipaddress='$ip';
$result =@mysql_query($sql, $dblink) ;
$sql2 = UPDATE stat SET filename ='$PHP_SELF' where ipaddress='$ip';
$result2 =@mysql_query($sql2, $dblink) ;
}
?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] debugging problems

2001-05-18 Thread elias

You forgot to select the database!

mysql_select_db($db_name);

-elias
http://www.eassoft.cjb.net

Taline Makssabo [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 This is a program i wrote to get some information at keep track with some
 stats. I am very new at this so bare with meI keep on getting this
 Warning:

 Warning: Supplied argument is not a valid MySQL result resource in
 /home/virtual/ppcu/home/httpd/html/php2/stat.php on line 13

 Warning: Supplied argument is not a valid MySQL-Link resource in
 /home/virtual/ppcu/home/httpd/html/php2/stat.php on line 17

 Whats wrong Is it my code? Please help.

 ?

 global $dblink,$PHP_SELF;
 $ip = getenv(REMOTE_ADDR);
 $host = getenv(HTTP_HOST);
 $browser = getenv(HTTP_USER_AGENT);
 $referer = getenv(HTTP_REFERER);
 $sql = SELECT ipaddress FROM stat WHERE ipaddress = '$ip';
 $connection = @mysql_connect(localhost, username, password) or
 die(Couldn't connect.);
 $db_name = contact;
 $table_name = stat;
 $result = @mysql_query($sql, $dblink);
 $num = mysql_num_rows($result);
 if( $num == 0 )
 {
 $sql =INSERT INTO stat(ipaddress,host,browser,referer,filename)
 VALUES('$ip', '$host', '$browser', '$referer','$PHP_SELF');
 $result=mysql_query($sql,$dblink);
 $sql1=INSERT INTO hits(ipaddress,count) VALUES('$ip',1);
 $result1=@mysql_query($sql1,$dblink);
 $text=you had a new visitor from IP: $ip, Host: $host Browser:
 $browser Referer: $referer;
 if ($result)
 {
 mail([EMAIL PROTECTED], You had a new visitor,$text, FROM:
 [EMAIL PROTECTED]);
 }
 }else{
 $sql = UPDATE hits SET count = count + 1 where ipaddress='$ip';
 $result =@mysql_query($sql, $dblink) ;
 $sql2 = UPDATE stat SET filename ='$PHP_SELF' where ipaddress='$ip';
 $result2 =@mysql_query($sql2, $dblink) ;
 }
 ?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] debugging problems

2001-05-18 Thread Don Read


On 18-May-01 Taline Makssabo wrote:
 This is a program i wrote to get some information at keep track with some
 stats. I am very new at this so bare with meI keep on getting this
 Warning:
 
 Warning: Supplied argument is not a valid MySQL result resource in
 /home/virtual/ppcu/home/httpd/html/php2/stat.php on line 13
 
 Warning: Supplied argument is not a valid MySQL-Link resource in
 /home/virtual/ppcu/home/httpd/html/php2/stat.php on line 17
 
 Whats wrong Is it my code? Please help.
 
 ?
 
 global $dblink,$PHP_SELF;
 $ip = getenv(REMOTE_ADDR);
 $host = getenv(HTTP_HOST);
 $browser = getenv(HTTP_USER_AGENT);
 $referer = getenv(HTTP_REFERER);
 $sql = SELECT ipaddress FROM stat WHERE ipaddress = '$ip';
   $connection = @mysql_connect(localhost, username, password) or
 die(Couldn't connect.);

Not too informative:
  die ('pproblems ' .mysql_errno() .'BR'.mysql_error().BR\n);

but anyhow, ok, you're connected.

   $db_name = contact;
   $table_name = stat;

What are these ?
are you missing mysql_select_db($db_name); ?

   $result = @mysql_query($sql, $dblink);
  
Test your queries !

if ($result) {

 $num = mysql_num_rows($result);
   if( $num == 0 )
 {
   $sql =INSERT INTO stat(ipaddress,host,browser,referer,filename)
 VALUES('$ip', '$host', '$browser', '$referer','$PHP_SELF');
   $result=mysql_query($sql,$dblink);
   $sql1=INSERT INTO hits(ipaddress,count) VALUES('$ip',1);
   $result1=@mysql_query($sql1,$dblink);
   $text=you had a new visitor from IP: $ip, Host: $host Browser:
 $browser Referer: $referer;
if ($result)
   {
   mail([EMAIL PROTECTED], You had a new visitor,$text,
FROM:
 [EMAIL PROTECTED]);
   }
   }else{
   $sql = UPDATE hits SET count = count + 1 where ipaddress='$ip';
   $result =@mysql_query($sql, $dblink) ;
   $sql2 = UPDATE stat SET filename ='$PHP_SELF' where ipaddress='$ip';
   $result2 =@mysql_query($sql2, $dblink) ;
 }
 ?
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]