garydt Posted March 27, 2007 Share Posted March 27, 2007 I'm making a website where registered users can upload a photo as well as information. The main page will display all of the users' photos. When user1 clicks on, say, user5's photo i want a page to open up and user5's information to be displayed. Is there a way to do this? Every user has a username stored in the database along with their information and the url to their photo. Code of the main page- <?php require_once('Connections/elvisdb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?><!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> <style type="text/css"> <!-- .style1 {color: #FFFFFF} .style3 {color: #000099} --> </style> </head> <body> <table width="1100" border="0" cellpadding="5"> <tr> <td width="151"><table width="150" bgcolor="#F48D02" border="0" cellpadding="0"> <tr> <td class="style3"> </td> </tr> </table></td> <?php mysql_select_db($database_elvisdb, $elvisdb); $query_Recordset1 = "SELECT * FROM images ORDER BY `count` DESC"; $Recordset1 = mysql_query($query_Recordset1, $elvisdb) or die(mysql_error()); while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { for ($i=1;$i<=3;$i++) { $totalRows_Recordset1 = mysql_num_rows($Recordset1); echo $i; ?> <td> <p><img src="<?php print $row_Recordset1['imageName']?>"></p> <p><?php print $row_Recordset1['usnm']?></p> </td> <?php if ($i=3) { ?> <br /> <?php } } } ?> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/ Share on other sites More sharing options...
only one Posted March 27, 2007 Share Posted March 27, 2007 very simple, just select from all the different tables where the information is stored, and where their username is.... Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-215965 Share on other sites More sharing options...
garydt Posted March 27, 2007 Author Share Posted March 27, 2007 Thanks. How do i pass an username from the main page to the next page when the logged-in user clicks on another user's photo to see that user's info? I'm guessing i can't use the session variable mm_username as thats taken up with the current logged-in user? As you can see, i use a while loop to display all the photos. Everytime it loops do i need to assign each photo a variable/session variable? If so how do i pass it to the next page to retrieve that user's info, (not the logged-in user's info)? I hope i explained it clearly. Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-215993 Share on other sites More sharing options...
joshi_v Posted March 27, 2007 Share Posted March 27, 2007 while displaying the photos , select user name for that photo from DB and pass it as a hidden variable with that photo. so when u click on that photo pass this hidden variable too. so that u can use it in query. I hope i could understans what u r trying! Regards, Joshi. Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-215994 Share on other sites More sharing options...
JasonLewis Posted March 27, 2007 Share Posted March 27, 2007 here is my step by step guide, with no code. 1. make a page which lists out all the users and have there username linked like this: view.php?user=$username 2. on the view to php page grab the username from the url using $_GET 3. have a query to select all information regarding that user. 4. display the information. quite simple really. Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-215996 Share on other sites More sharing options...
garydt Posted March 27, 2007 Author Share Posted March 27, 2007 Thanks very much. I will try writing the code for that Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216000 Share on other sites More sharing options...
jitesh Posted March 27, 2007 Share Posted March 27, 2007 Set links like this <a href='user_info.php?userid='.$userid[$i]>Username</a> in 'user_info.php' get userid like this $userid = $_GET['userid']; Then you can fetch data like this "SELECT * FROM user WHERE UserID =".$userid; Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216004 Share on other sites More sharing options...
garydt Posted March 27, 2007 Author Share Posted March 27, 2007 Thanks alot. Heres what i've got- main page <?php mysql_select_db($database_elvisdb, $elvisdb); $query_Recordset1 = "SELECT * FROM images ORDER BY `count` DESC"; $Recordset1 = mysql_query($query_Recordset1, $elvisdb) or die(mysql_error()); while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { $uname = $row_Recordset1['usnm']; for ($i=1;$i<=3;$i++) { $totalRows_Recordset1 = mysql_num_rows($Recordset1); echo $i; echo $usernm; ?> <td><p><a href="userpage.php?$userid='.$uname'"><img src="<?php print $row_Recordset1['imageName'] ?>"></a></p> userpage <?php session_start(); ?> <?php require_once('Connections/elvisdb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $user = $_GET['userid']; $colname_Recordset1 = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']); } mysql_select_db($database_elvisdb, $elvisdb); $query_Recordset1 = sprintf("SELECT * FROM userinformation WHERE usernm = $uname", GetSQLValueString($colname_Recordset1, "text")); $Recordset1 = mysql_query($query_Recordset1, $elvisdb) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $colname_Recordset2 = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_Recordset2 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']); } mysql_select_db($database_elvisdb, $elvisdb); $query_Recordset2 = sprintf("SELECT * FROM images WHERE usnm = $uname", GetSQLValueString($colname_Recordset2, "text")); $Recordset2 = mysql_query($query_Recordset2, $elvisdb) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); $img = $row_Recordset2['imageName']; $big = $row_Recordset2['bigimagename']; echo $img; When i click on a photo and the userpage opens i get- 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/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216062 Share on other sites More sharing options...
garydt Posted March 27, 2007 Author Share Posted March 27, 2007 I've put this- <td><p><a href="userpage.php?username=$uname"><img src="<?php print $row_Recordset1['imageName'] ?>"></a></p> But it doesn't pass on as a variable, only as $uname I got this on userpage $user = $_GET['username]; What have i done wrong? Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216236 Share on other sites More sharing options...
garydt Posted March 27, 2007 Author Share Posted March 27, 2007 any suggestions? Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216314 Share on other sites More sharing options...
Edward Posted March 27, 2007 Share Posted March 27, 2007 Hey, I'm not too advanced but I think I might be able to give you some tips. Your Code: <td><p><a href="userpage.php?$userid='.$uname'"><img src="<?php print $row_Recordset1['imageName'] ?>"></a></p> New Code: <td><p><a href="userpage.php?userid=<?php echo $uname; ?>"><img src="<?php print $row_Recordset1['imageName'] ?>"></a></p> Firstly, see that I removed the dollar sign for the variable in the URL (but importantly, not for the value). Secondly, assuming you were showing me your code in its full context, the quotes seemed over complex. I have reduced these and only moved from HTML to PHP and back to display the relevent username in the URL, which was necessary so that $username will display the username, as opposed to displaying '$username'. I think it would also help you to be more consistent with your naming of data. For example, you have given the 'username' four different names throughout your site. The database uses 'usnm' The main page uses 'uname' The URL uses 'userid' The User page 'user' Perhaps change them all to 'username', or 'database_username' and 'website_username' if you really want to distinguish them. Hopefully that might help, if not, post back. Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216335 Share on other sites More sharing options...
garydt Posted March 27, 2007 Author Share Posted March 27, 2007 Thanks alot, that did it! Link to comment https://forums.phpfreaks.com/topic/44464-solved-how-to-open-page-and-make-sure-users-sees-the-right-information/#findComment-216418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.