Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 1st, 2004, 09:38 AM
Registered User
 
Join Date: Apr 2004
Location: , , .
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";
}
?>
Reply With Quote
  #2 (permalink)  
Old April 1st, 2004, 10:54 AM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind, sorted it now!

Reply With Quote
  #3 (permalink)  
Old April 22nd, 2004, 03:49 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
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.

Reply With Quote
  #4 (permalink)  
Old April 22nd, 2004, 01:51 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
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/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.