Jump to content

[SOLVED] What wrong with this? User ID seems to wreck it...


forumnz

Recommended Posts

Heres the code. Its meant to pull certain variables from a database based on the users id.

 

<?php
session_start();
$userid=$_SESSION['userid'];
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<?php

$database=mysql_connect("localhost","user", "pass");



mysql_select_db("test",$database);

$query="select * from members WHERE userid=$userid";

$result=mysql_query($query);

while($img=mysql_fetch_assoc($result)){

$image_num=$img['stg1'];

if($image_num=="0"){

echo"<img src='images/not_completed.gif' />";

}elseif($image_num=="1"){

echo"<img src='images/completed.gif' />";

}else {

echo" sorry there is no images to show";

}
}
?>

</body>
</html>

Link to comment
Share on other sites

  • Replies 92
  • Created
  • Last Reply

just change

 

mysql_select_db("test",$database);

 

$query="select * from members WHERE userid=$userid";

 

 

to

 

mysql_select_db("test",$database);

echo $userid;

$query="select * from members WHERE userid=$userid";

 

 

and refresh the page do you see any numbers?

Link to comment
Share on other sites

It comes up with this error:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/designervision.co.nz/httpdocs/clients/progress.php on line 81

 

Line 81 is:

while($img=mysql_fetch_assoc($result)){

Link to comment
Share on other sites

ok so the $userid didn't echo any number.. thats the problem right there

 

your cant fetch any mysql result from a corrupt SQL query  u gotta figure out why your session's not setting userid field that page has no errors

 

if its a number it doesnt need quotes it would work

 

you have to look at your other pages like login.php or w/e  where userid is set to sessions maybe its missing

Link to comment
Share on other sites

Woo Ok i got it almost!

 

I edited the login page and now the first page does come up with a number (3, which is the users id).

 

It still displays everyones images though.

3
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/designervision.co.nz/httpdocs/clients/progress.php on line 81

Link to comment
Share on other sites

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

well..  '' means something is empty i belive the $userid is empty again or whatever that error comes from

 

what is on line 1 anyways?

Link to comment
Share on other sites

I would try this:

 

$database = mysql_connect("localhost","user", "pass");
mysql_select_db("test", $database);
$query = "SELECT * FROM members WHERE userid = '" . $userid . "'";
$result = mysql_query($query);

 

I'm a bit confused with the $database thing.... Why is your mysql_connect a variable?

Link to comment
Share on other sites

Is userid in your db table `members`? If so it must be exactly as it is in the table.

 

I got one of those errors earlier today. It turned out the only thing I had wrong was the syntax in my query. I thought it was strang that it said line 1 because line 1 is always <?PHP session_start();  for me.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.