forumnz Posted February 17, 2007 Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/ Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 so whats the error than?? where is userid set to session Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187272 Share on other sites More sharing options...
Greaser9780 Posted February 17, 2007 Share Posted February 17, 2007 Change this: userid=$userid"; to this: userid='$userid'"; Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187274 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 It now comes up with his 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/test.php on line 26 Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187284 Share on other sites More sharing options...
Greaser9780 Posted February 17, 2007 Share Posted February 17, 2007 In you SELECT FROM statement I don't see anything that you tried to select from your table. $query="select * `what?` from members WHERE userid=$userid"; Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187288 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 like i said your $userid is nothing.. u gotta figure out why isn't it set do echo $userid; before the $sql query gets built Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187292 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 I really dont know what to do?? What must be used for it to work? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187303 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187304 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187312 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187316 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 If i post it would you please have a look at my login page? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187319 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187342 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187364 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 change also back on that page not login but process.php $result=mysql_query($query); to $result = mysql_query($query) or die(mysql_error()); for more error checking Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187373 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Ok, It now says 4Unknown column 'userid' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187377 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 does userid column exist in your database called test table members Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187379 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks fixed!! Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187396 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Oh oh.... It now comes up with this error if I login as someone else: 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 Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187424 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187427 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 This is on line one in progress.php <?php require("require.php"); ?> Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187434 Share on other sites More sharing options...
bobleny Posted February 17, 2007 Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187459 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 see u gotta open require.php it must have some SQL query in there that has a problem as well wait a second thats not line 1 man thats line 1 of the first php prase I believe its the next <?php or <? not that one.. Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187460 Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Well this is the next php code: <?php include("../menu.php"); ?> Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187465 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 Nope thats not it either line 1 of the code that gives the error <? sutff ?> <?php dfsdfds ?> <?php blahblah ?> <?php <- this is line 1 error ?> Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187468 Share on other sites More sharing options...
Greaser9780 Posted February 17, 2007 Share Posted February 17, 2007 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 https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/#findComment-187473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.