JasonLewis Posted February 17, 2007 Share Posted February 17, 2007 you said before, its $_SESSION['userid'] if you look at the top of the code on the first page Greaser9780 you can see $userid is defined. try this forumnz: <?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) or die("Error in query: ".mysql_error()); if(mysql_num_rows($result) > 0){ echo "We are getting a result!"; } 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> tell me if anything outputs to the screen. Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187586 Share on other sites More sharing options...
Greaser9780 Posted February 17, 2007 Share Posted February 17, 2007 It was in on the first code but then he revised it on the 3rd page of this topic Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187587 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Yes Greaser. ProjectFear - it still came up with a blank page. Could it be the cookie? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187590 Share on other sites More sharing options...
sspoke Posted February 18, 2007 Share Posted February 18, 2007 when you right click your page and click View Source notepad opens up whats inside it? sometimes headers return blank pages but there is still data there Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187591 Share on other sites More sharing options...
JasonLewis Posted February 18, 2007 Share Posted February 18, 2007 It was in on the first code but then he revised it on the 3rd page of this topic fair enough then, too many pages. what is in the require.php page then... Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187592 Share on other sites More sharing options...
sspoke Posted February 18, 2007 Share Posted February 18, 2007 O ya try adding a die("cant connect to sql"); too $database=mysql_connect("localhost","user", "pass") or die("cant connect to sql"); u never know you might not even be connecting to your SQL Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187593 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 This is the output code: <!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> </body> </html> and this is require.php <?php /// require.php session_start(); if (!$_SESSION['username']){echo('<meta http-equiv="Refresh" content="0;url=clientlogin.php" />Please Log In'); }; $username = $_SESSION['username']; $password = $_SESSION['password']; ?> Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187594 Share on other sites More sharing options...
JasonLewis Posted February 18, 2007 Share Posted February 18, 2007 well by that you havnt defined the variable $userid, unless your going to user $username. $userid should be $_SESSION['userid'] which you had on the first page. (this question shouldn't have gone over 4 pages... nearly 5) Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187595 Share on other sites More sharing options...
sspoke Posted February 18, 2007 Share Posted February 18, 2007 so its finally solved! Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187597 Share on other sites More sharing options...
JasonLewis Posted February 18, 2007 Share Posted February 18, 2007 so its finally solved! huh? i dont think so, i was just saying that it shouldnt have gone this long! Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187600 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 tried that. Not working still. Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187664 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 Change this <?php $result = mysql_query($query) or die(mysql_error()); ?> to <?php $result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error()); ?> Does it display anything? Ken Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187667 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 IN progress.php? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187671 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Nope not working?? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187677 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Anyone? :-\ Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187687 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 These one line answers without explanation don't help. Please post the current non-working code with an explanation of what isn't working. Somebody coming into this discussion now is not going to read through all 60+ responses to try to figure out what is wrong. Ken Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187692 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Alright sorry. Heres what I want to happen. 1. User log in 2. User clicks on link to progress.php 3. 5 images show up on this page. Each of the images are one of two and what they are depends on whether a 1 or a 0 is present in the database. For each user there will be different ones showing - depending on what the numbers are (1 or 0). I am trying to get a users images to be displayed using their unique ID which should be set when the log in. Here is the code which has the images (please note - for ease purpose, I have shortened it to one image). <?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) or die("Error in query: ".mysql_error()); if(mysql_num_rows($result) > 0){ echo "We are getting a result!"; } 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> Here is the login: <?php session_start(); ?> <?php /// connect to database require("config.php"); $con=mysql_connect($mysql_hst,$mysql_us,$mysql_ps); if (!$con) { die('Could not connect: ' . mysql_error() . '<br /><br />Check your config file or contact your server support team.'); }; /// select DB if (!mysql_select_db($mysql_db, $con)){die ("Could not connect to the database you specified. Make sure it exists and is correctly named within config.php");}; $_SESSION['username'] = str_replace(' ','/space',strtolower(mysql_real_escape_string($_POST[username]))); $_SESSION['password'] = base64_encode($_POST[password]); /// connect to database $con=mysql_connect($mysql_hst,$mysql_us,$mysql_ps); if (!$con) { die('Could not connect: ' . mysql_error() . '<br /><br />Check your config file or contact your server support team.'); }; /// select DB if (!mysql_select_db($mysql_db, $con)){die ("Could not connect to the database you specified. Make sure it exists and is correctly named within config.php");}; if ($_POST["username"] == ""){die ('<meta http-equiv="Refresh" content="0;url=error.php?li=Please+enter+valid+details" />');}; if ($_POST["password"] == ""){die ('<meta http-equiv="Refresh" content="0;url=error.php?li=Please+enter+valid+details" />');}; $password = base64_encode($_POST[password]); $username = str_replace(' ','/space/',mysql_real_escape_string(strtolower($_POST[username]))); $found = 0; /// if exists $ifexists = mysql_query("SELECT * FROM members"); while($row = mysql_fetch_array($ifexists)) { if ($row[username] == $username){ /// check password if ($row[password] == $password){ ///check active if ($row[active] == "1") {$found = "1";$_SESSION['userid'] = $row[id];$_SESSION['userid'] = $row[id];} else {echo ("Account has not been activated - Check Your Email");};} else {echo('<meta http-equiv="Refresh" content="0;url=error.php?li=Please+enter+valid+details" />');};};}; if ($found == "0") {die('<meta http-equiv="Refresh" content="0;url=error.php?li=Please+enter+valid+details" />');}; if ($found == "1") {echo('<meta http-equiv="refresh" content="1; URL=index.php" />');}; ?> and if needed, here is require.php <?php /// require.php session_start(); if (!$_SESSION['username']){echo('<meta http-equiv="Refresh" content="0;url=clientlogin.php" />Please Log In'); }; $username = $_SESSION['username']; $password = $_SESSION['password']; ?> It currently displays this error: 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/page/3/#findComment-187697 Share on other sites More sharing options...
JasonLewis Posted February 18, 2007 Share Posted February 18, 2007 i'm pretty sure that error means one of your variables, possibly $userid is blank. Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187701 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 What do I do about this please? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187709 Share on other sites More sharing options...
JasonLewis Posted February 18, 2007 Share Posted February 18, 2007 echo $userid and see if anything is showing. if its not there is something wrong with your login. Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187714 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Nothing shows up. Blank screen. =( Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187717 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 What could be wrong with the login? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187721 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Someone help please? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187750 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 Please don't bump the thread so quickly -- wait at least 3 or 4 hours. You need to learn how to debug PHP scripts. Put echo statements at key places where you think the script is failing. Also, since it looks like you're having problems getting a value from the $_SESSION array, put this line: <?php echo '<pre>' . print_r($_SESSION,true) . '</pre>'; ?> immediately after the "session_start()" in the script that's failing. If you don't see the value you're looking for in the $_SESSION array, look at the routine where you think you're setting it and put echo statements there too. If you use correct debugging techniques, you should be able to determine what is going wrong. Ken Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187757 Share on other sites More sharing options...
forumnz Posted February 18, 2007 Author Share Posted February 18, 2007 Excellent I have something now. I did that and out popped this: Array ( [username] => admin1122 [password] => YWRtaW4= [userid] => ) This is a test username and password exactly like it is in the database. This users ID is 4 in the db but its not showing here. Does that mean when the user logs in its not setting the userid as well? Link to comment https://forums.phpfreaks.com/topic/38936-solved-what-wrong-with-this-user-id-seems-to-wreck-it/page/3/#findComment-187758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.