Doug Posted February 26, 2011 Share Posted February 26, 2011 Hello, I have run into a problem with my program that I can't seem to solve. I have a file of images that I want to be able to click on to show a larger version of the same image. The images will have been uploaded by users who will have through a database. the images are also there. I have done this but at the moment when a user clicks on the mage to get a larger one the "user_id" to identify the image is missing: http://localhost/mysitename/pictures1.php?user_id= How can I get the program to pick up the user_id. any help would most gladly appreciated. Code of both programs below. //this displays the smaller images <?php require_once('appvars.php'); require_once('connectvars1.php'); // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); // Retrieve the user data from MySQL $query = "SELECT picture, name FROM pictures order by join_date desc"; $data = mysqli_query($dbc, $query); // Loop through the array of user data, formatting it as HTML echo '<h4>Pictures:</h4>'; $picture_id = $row['user_id']; echo '<table>'; while ($row = mysqli_fetch_array($data)) { if (is_file(MM_UPLOADPATH . $row['picture']) && filesize(MM_UPLOADPATH . $row['picture']) > 0) { echo '<img src="' . MM_UPLOADPATH . $row['picture'] . '" alt="' . $row['name'] . '" style="width:150px; maxheight=110px; margin: 5px; padding: 5px" /> <a href=pictures1.php?user_id=' . $picture_id . '>' . $row['name'] . '</a>'; } } echo '</table>'; mysqli_close($dbc); ?> //This displays the larger version <?php session_start(); ?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mismatch - View Profile</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h3>Mismatch - View Profile</h3> <?php require_once('appvars.php'); require_once('connectvars1.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login1.php">log in</a> to access this page.</p>'; exit(); } else { echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>'); } // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); // Grab the profile data from the database if (!isset($_GET['user_id'])) { $query = "SELECT name, picture FROM pictures WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT name, picture FROM pictures WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table>'; if (!empty($row['name'])) { echo '<tr><td class="label">name:</td><td>' . $row['name'] . '</td></tr>'; } if (!empty($row['picture'])) { echo '<tr><td class="label">Picture:</td><td><img src="' . MM_UPLOADPATH . $row['picture'] . '" alt=" Picture" /></td></tr>'; } echo '</table>'; if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) { echo '<p>Would you like to <a href="editprofile1.php">edit your profile</a>?</p>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your picture.</p>'; } mysqli_close($dbc); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/228909-tranferring-a-value-tovariable-please-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.