runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 what script am i changing to not to use £_GET?? is it the image 1 or the login or just the profile page itself :S Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted December 5, 2007 Share Posted December 5, 2007 Do you understand what $_GET is? How it works? And how it is used? If you dont, I suggest you start here: http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 would this work>> <?$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' $_SESSION['user_id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.yourdomain.com/members/images/' $_SESSION['user_id'] '.' . $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } ?> tried it but getting syntax error, unexpected T_VARIABLE one 1st line Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 would this work>> <?$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' $_SESSION['user_id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.yourdomain.com/members/images/' $_SESSION['user_id'] '.' . $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } ?> tried it but getting syntax error, unexpected T_VARIABLE one 1st line Use this, instead. It has no syntax errors: <?php $sql = "SELECT `ext` FROM `user_image` WHERE `user_id`=".$_SESSION['user_id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.yourdomain.com/members/images/'". $_SESSION['user_id'] . '.' . $row['ext'] . " />"; } }else{ echo 'Error: Image not found.'; } ?> Sam Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 hey thnaks sadly the script is still not displaying the image ?? Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 Sorry, that's because we had an extra ' in the code <?php $sql = "SELECT `ext` FROM `user_image` WHERE `user_id`=".$_SESSION['user_id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.yourdomain.com/members/images/". $_SESSION['user_id'] . "." . $row['ext'] . "' />"; } }else{ echo 'Error: Image not found.'; } ?> That ought to work now Sam Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 sadly its still not displaying any images... is there somthing extra need ? Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 <?php $sql = "SELECT `ext` FROM `user_image` WHERE `user_id`=".$_SESSION['user_id']; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.yourdomain.com/members/images/". $_SESSION['user_id'] . "." . $row['ext'] . "' />"; } }else{ echo 'Error: Image not found.'; ?> Try it with the 'mysql_error' part on the query. Also with the first if statement it's just if($q)... if $q is what? set, empty etc..? The second if statement is if(!empty($row)), which is like a double negative in English, if $row is not not full.. So you might want to try if(isset($row)){ } If that doesn't work you might want a while loop.. Something along the lines of <?php $sql = "SELECT `ext` FROM `user_image` WHERE `user_id`=".$_SESSION['user_id']; $q = mysql_query($sql); if(isset($q)){ while ($row = mysql_fetch_array($q)) { echo "<img src='http://www.yourdomain.com/members/images/". $_SESSION['user_id'] . "." . $row['ext'] . "' />"; } } else{ echo 'Error: Image not found.'; } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 $sql = "SELECT `ext` FROM `user_image` WHERE `user_id`=".$_SESSION['user_id']; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.yourdomain.com/members/images/". $_SESSION['user_id'] . "." . $row['ext'] . "' />"; } }else{ echo 'Error: Image not found.'; gimmies nexpected $end Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted December 5, 2007 Share Posted December 5, 2007 Unexpected end means that you forgot to close a statement. In this case, you didn't close the if statement. $sql = "SELECT `ext` FROM `user_image` WHERE `user_id`=".$_SESSION['user_id']; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.yourdomain.com/members/images/". $_SESSION['user_id'] . "." . $row['ext'] . "' />"; } }else{ echo 'Error: Image not found.'; } Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted December 5, 2007 Share Posted December 5, 2007 Just as a side note, you can use an if statement like this: if($q) // some code else //some other code This is without any brackets. However if you are adding brackets, there must be ones in every area required. Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 I don't understand why your querying the database at all, seems a waste of resources. <?php if (isset($_SESSION['user_id'])) { foreach(array('jpg','gif','png') as $ext) { // add valid file extensions here. if (file_exists('members/images/' . $_SESSION['user_id'] . '.' . $ext)) { echo '<img src="members/images/{$_SESSION['user_id']}.$ext" />'; } } } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 THIS wouldent work tho would it ? '<img src="members/images/{$_SESSION['user_id']}.$ext" /> Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 If the path is correct why not? Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 Actually, didn't even notice that. it would need to be.... echo "<img src='members/images/{$_SESSION['user_id']}.$ext' />"; Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 humm its not displaying any image posted :S Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 Are the paths correct? Do files exist that corrispond to the $_SESSION['user_id'] variable? Honestly, we can't do everything. The code is perfectly valid, might just need some adjustments. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted December 5, 2007 Share Posted December 5, 2007 I think his $_SESSION['user_id'] is the username, not the id field we all think it is... runnerjp, everyone has given you everything you need to get this working. You need to make some effort to connect the dots. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 question ... can i get the username from whats typed in the url e.g www.runningprofiles.com/members/user so i can get user name form that? then frind id with username Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 $_SESSION['user_id'] does supposdly get the users id Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 if the url was www.runningprofiles.com/members/user/index.php?username=helraizer (website doesn't actually exist) $usrname = $_GET['username'] - the username would be helraizer. For instance. Then query the database SELECT * FROM `table` WHERE `username`= $username (or similar) then use a while loop, like in the last example I gave. Use that to find the id associated with that username. Sam Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 question ... can i get the username from whats typed in the url Yes, and I have previousy provided you with code (for your profile system) that does just that. As I said when I gave you that example, learn from it. Its no good simply having code handed to you unless you understand it. If you understood the code I provided you with over a week ago, you wouldn't be asking this same question. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 i am currently using $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } could i not just array the id??? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 OK BEEN MESISNG AROUND WITH IT AND I HAVE NEARLY GOT IT $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' $pID; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' "$pID" '.' . $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } BUT THE CODE DOESNT WORK DO TO unexpected T_VARIABLES $pID gets the users id! Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 Where did $pID come from? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.