Jump to content

Php displaying ID=1 for all ID's


pukstpr12

Recommended Posts

ok, i am a bit of a php newbie here so i am hoping this is something that can be figured out pretty easily

 

I created a website to display pictures i have taken. I create the rows in phpmyadmin with the image source and insert the code into the body. /photo.php?id=1 displays picture 1, but the problem is that /photo.php?id=2 displays picture 1 also, despite a different image source in the row. The thing is also, that /photo.php?id=3 displays image 1 also even though there is no row 3 in the database.

 

Can anyone help?

 

<?php echo $row_Photo['id']; ?>
              <?php echo $row_Photo['photopath']; ?>

Link to comment
Share on other sites

you must show the rest of your code

but i think you didn't told the page wich id you want

do you have something like this in your page

include("config.php");
$id=$_GET['id'];
mysql_connect($server, $datauser, $datapass) or die (mysql_error());
$result = mysql_db_query($database, "select * from $table where id='$id'") or die (mysql_error());
if (mysql_num_rows($result)) {
  $qry = mysql_fetch_array($result);

$img=$qry['your image name or whatever in your sql'];

then try <img src="<?php echo $img; ?>"/>

Link to comment
Share on other sites

Sorry, here is the full code

 

<?php require_once('Connections/Photo.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;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Photo = 1;
$pageNum_Photo = 0;
if (isset($_GET['pageNum_Photo'])) {
  $pageNum_Photo = $_GET['pageNum_Photo'];
}
$startRow_Photo = $pageNum_Photo * $maxRows_Photo;

mysql_select_db($database_Photo, $Photo);
$query_Photo = "SELECT * FROM photos";
$query_limit_Photo = sprintf("%s LIMIT %d, %d", $query_Photo, $startRow_Photo, $maxRows_Photo);
$Photo = mysql_query($query_limit_Photo, $Photo) or die(mysql_error());
$row_Photo = mysql_fetch_assoc($Photo);

if (isset($_GET['totalRows_Photo'])) {
  $totalRows_Photo = $_GET['totalRows_Photo'];
} else {
  $all_Photo = mysql_query($query_Photo);
  $totalRows_Photo = mysql_num_rows($all_Photo);
}
$totalPages_Photo = ceil($totalRows_Photo/$maxRows_Photo)-1;

$queryString_Photo = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Photo") == false && 
        stristr($param, "totalRows_Photo") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Photo = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Photo = sprintf("&totalRows_Photo=%d%s", $totalRows_Photo, $queryString_Photo);
?>

Link to comment
Share on other sites

change

$query_Photo = "SELECT * FROM photos";

to

$ID = (int)$_GET['ID'];
$query_Photo = "SELECT * FROM photos WHERE ID=$ID";

 

or probably better to use:

 

$ID = (int)$_GET['ID'];
$query_Photo = (isset($_GET['ID']))?"SELECT * FROM photos WHERE ID=$ID":"SELECT * FROM photos";

tried, but to no avail. still have the problem. thank you for your response though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.