Page 1 of 2
Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Sun Aug 02, 2009 7:27 pm
by tobimichigan
Hi there code gurus,
Please Chief McInfo, Sir Jack and other honorable code gurus, I need a sharp pointer as to why this error keeps coming up:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\www\Members.Arena\actions\Members_Area.php on line 24
Code: Select all
<?php
session_start();
if (!$_SESSION["pfno"])
{
//user not logged in, redirect to login page
header("Location:Login.php");
}
include("cn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<a href="Members_Area.php">Members Area</a> | <a href="Edit_Profile.php">Edit Profile</a> | <a href="Reports.php">Reports</a> | <a href="Logout.php">Logout</a>
<?php
$pfno=$_GET["pfno"];
$user=mysql_query("Select * From user_table where pfno='$pfno'");
//$result=mysql_query($query,$link);
$user = mysql_fetch_assoc($pfno);
//Display Member Information
echo ("<p>Welcome PFNO: ".$_SESSION["pfno"]);
echo ("<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"]));
?>
</body>
</html>
I am actually trying to retrieve unique members information from multiple tables say table_a and perhaps table_b as well.
Please kindly point to where "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\www\Members.Arena\actions\Members_Area.php on line 24" is coming from.
line 24=$user = mysql_fetch_assoc($pfno);
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Sun Aug 02, 2009 9:16 pm
by SidewinderX
Have you established a connection to your database? Your code is also vulnerable to SQL injections.
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 3:11 am
by tobimichigan
SidewinderX wrote:Have you established a connection to your database? Your code is also vulnerable to SQL injections.
Of course, check line 10...
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 6:05 am
by SidewinderX
Line 10 doesn't exactly jump out and say mysql_connect to me. But as the error suggests, $pfno is not a valid mysql resource. You want to use $user.
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 6:40 am
by tobimichigan
SidewinderX wrote:Line 10 doesn't exactly jump out and say mysql_connect to me. But as the error suggests, $pfno is not a valid mysql resource. You want to use $user.
Please could u visually demonstrate your points with precise codes?
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 7:45 am
by SidewinderX
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 7:53 am
by jackpf
Use "or die(mysql_error())" with the query.
Chances are your query is failing.
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 8:41 am
by tobimichigan
jackpf wrote:Use "or die(mysql_error())" with the query.
Chances are your query is failing.
Sir Jack heres the problem
Hello code gurus,
Please I need a charp pointer as to why in the member_area, the value of pfno in the table which is also the username is not echoing out on the screen.
Login:
Code: Select all
<?php
session_start();
include("cn.php");
$msg = "";
//require_once('actions/'.$action.'.php');
if (isset($_POST['Submit']))
{
$username = $_POST['pfno'];
$password = $_POST['ledgerno'];
$result = mysql_query("Select * From user_table where pfno='$pfno'",$link);
//if(mysql_num_rows($result)>0)
{
//$row = mysql_fetch_array($result, MYSQL_BOTH);
if($ledgerno == $row["ledgerno"])
{
$_SESSION['adminok'] = "ok";
$_SESSION['pfno'] = "pfno";
$_SESSION['ledgerno'] = "ledgerno";
$_SESSION['valid_time']=time();
header("Location: Members_Area.php?pfno=".$_SESSION['pfno']);
}
else
{
$msg = "ledgerno incorrect";
}
}
//else
{
$msg = "pfno incorrect";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<body>
<div align="center"><img src="../../images/LasustaffCoop2.jpg" alt="" name="LasuStaffCams_Logo" width="700" height="150" id="LasuStaffCams_Logo" /></div>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Members Logon </strong></td>
</tr>
<tr>
<td width="78">PF NO. </td>
<td width="6">:</td>
<td width="294"><input name="pfno" type="text" id="pfno"></td>
</tr>
<tr>
<td>LEDGER NO. </td>
<td>:</td>
<td><input name="ledgerno" type="password" id="ledgerno"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
members_area
Code: Select all
<?php
session_start();
if (!$_SESSION["pfno"])
{
//user not logged in, redirect to login page
header("Location:Login.php");
}
include("cn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LASUSTAFFCAMS MEMBERS</title>
</head>
<body>
<a href="Members_Area.php">Members Area</a> | <a href="Edit_Profile.php">Edit Profile</a> | <a href="Reports.php">Reports</a> | <a href="Logout.php">Logout</a>
<?php
$pfno=$_GET["pfno"];
$result=mysql_query("Select * From user_table where pfno='$pfno'") or die (mysql_error());
//$result=mysql_query($query,$link;
$user = mysql_fetch_assoc($result);
echo mysql_num_rows($result);
//Display Member Information
echo ("<p>Welcome user" .$user["pfno"]);
echo ("<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"]));
?>
</body>
</html>
I just need it to display the member pfno value on the table on the member_area page.
Here's the table
CREATE TABLE `user_table` (
`id` bigint(20) NOT NULL auto_increment,
`pfno` varchar(255) NOT NULL,
`ledgerno` varchar(255) NOT NULL,
`fname` text NOT NULL,
`oname` text NOT NULL,
`lname` text NOT NULL,
`soorigin` text NOT NULL,
`lga` text NOT NULL,
`Nationalty` text NOT NULL,
`email` text NOT NULL,
`residentialadd` text NOT NULL,
`department` text NOT NULL,
`amountd` text NOT NULL,
`sex` text NOT NULL,
`regdate` date NOT NULL,
`session` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='cUser - User Table' AUTO_INCREMENT=2 ;
Sir Jack please help point out why its not doing this...
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 8:54 am
by jackpf
It looks like $_SESSION['pfno']'s value is 'pfno'.
Is there a user called 'pfno'? Do you not mean $pfno?
Also, why are you passing a session in the url? It's already in a session.
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 5:45 pm
by tobimichigan
jackpf wrote:It looks like $_SESSION['pfno']'s value is 'pfno'.
Is there a user called 'pfno'? Do you not mean $pfno?
Also, why are you passing a session in the url? It's already in a session.
There's no user called pfno, this is just a name of a column in the database. It holds a four digt xter which I intend dispaying for the current user. It is also serving as a username to authenticate users into the databse schema.
What I need rigt now is how to
Code: Select all
<?php echo ("Welcome PFNO: $pfno");?>
such that $pfno would be the actual 4 digit code for a unique user.Thereafter mysql_fetch_assoc would get information form other tables unique to this user.
This is all. So how do I do this with the above code?
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 6:03 pm
by SidewinderX
What in the world is $_GET["pfno"]?
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 6:39 pm
by tobimichigan
SidewinderX wrote:What in the world is $_GET["pfno"]?
Its an array winder, getting all possible login names in the html-form login.. do u have any better ideas?
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Mon Aug 03, 2009 8:34 pm
by SidewinderX
$_GET is an array, $_GET["pfno"] is some value. What value are you expecting it to have? I was trying to make sense of your SQL query. You are selecting pfno your database where pfno=$_GET["pfno"], thus $user['pfno'] equals $_GET["pfno"] rendering your query quite useless.
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Tue Aug 04, 2009 6:52 am
by jackpf
Also, you're selecting where pfno=$pfno, but I don't see where $pfno has been set. Don't you mean $username?
And exactly - you're assing $_SESSION['pfno'] to 'pfno' what's the point?
I think you need to go back and read your own code.
Re: Warning: mysql_fetch_assoc(): supplied argument is not a
Posted: Tue Aug 04, 2009 10:57 am
by SidewinderX
From what I can tell, $pfno is $_GET["pfno"]