Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2004, 09:38 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sessions

Im trying to follow the book's section on Access Logger but keep getting the error on line 16 which refers to
if(!mysql_num_rows($result)) return 0;

what am i doing wrong?

Warning: Supplied argument is not a valid MySQL result resource in /home/ajay/public_html/auth_user.php on line 16
Authorisation failed. Login
Membership



$register_script = "./register.php";

function auth_user($userid, $password1) {
global $ajay_db, $Customer;

$connection = db_connect();
$query = "SELECT username FROM $Customer WHERE userid = '$userid' AND password1 = password('$password1')";

$result = mysql_query($query);

if(!mysql_num_rows($result)) return 0;
else {
$query_data = mysql_fetch_row($result);
return $query_data[1];
}
}

function login_form() {
global $PHP_SELF;
?>

<HTML>
<HEAD>
</HEAD>
<BODY>

<FORM METHOD="POST" ACTION="<? echo $PHP_SELF ?>">
User ID:
<INPUT TYPE="TEXT" NAME="userid" SIZE="8">
<BR>
Password:
<INPUT TYPE="PASSWORD" NAME="password1" SIZE="8">
<BR>
<INPUT TYPE="SUBMIT" VALUE="LOGIN" NAME="Submit">
</BODY>
</HTML>

<?
}

session_start();
if(!isset($userid)) {
login_form();
exit;

}
else {
session_register("userid", "password1");
$username = auth_user($userid, $password1);
if(!$username) {
session_unregister("userid");
session_unregister("password1");
echo "Authorisation failed. ";
echo "<A HREF=\"$PHP_SELF\">Login</A><BR>";
echo "<A HREF=\"$register_script\">Membership</A>";
exit;
}
else echo "Welcome, $username";
}
?>
 
Old April 1st, 2004, 10:54 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind, sorted it now!

 
Old April 22nd, 2004, 03:49 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

hi, please help....
why is invalid?
error message:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\php\general\intro.php on line 20


code attach:
<?php // file general/intro.php

include("mylibraryconnect.inc.php");
$connID = connect_to_mylibrary();

?>

<html><head>
<meta http-equiv="Content-Type"
      content="text/html; charset=iso-8859-1" />
<title>PHP Programming, intro sample</title>
</head><body>

<?php

$result = mysql_query("SELECT COUNT(*) FROM titles");
echo "<p>Table <i>titles</i> contains " .
  mysql_result($result, 0, 0) .
  " records.</p>\n";

  show_copyright(); // defined in mylibraryconnect.inc.php

?>

</body></html>

thanks.

 
Old April 22nd, 2004, 01:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That means that your query failed. If mysql_query() fails, then $result is FALSE, which is not a valid resource handle.

You need to call mysql_error() to get the actual error message from MySQL as to why the query failed.

You should do this after ALL mysql functions are called, including _connect(), _select_db(), _query(), etc...


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sessions aegron BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 4 December 19th, 2005 07:49 AM
sessions p2ptolu Classic ASP Components 3 March 17th, 2005 06:31 AM
Sessions 2540EA BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 20th, 2005 05:42 AM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM
Help sessions ittorget Pro VB 6 2 April 20th, 2004 02:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.