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
https://forums.phpfreaks.com/topic/69391-php-displaying-id1-for-all-ids/
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; ?>"/>

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);
?>

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";

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.

Have you looked at the data to make sure the IDs are actually different?

Yes I have. I also had a line that displayed the ID# next to the image. Even when the address bar read id=2, the picture and the ID# next to the image belonged to that of id=1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.