Jump to content

problem with


Recommended Posts

I have a gallery of pics when you click a pic you get sent to this page. Problem is I can't get the image to display. I know it's a GET function or img src="" but I can't get it right. This is my output. No styling yet. This is a template for all photos when clicked I want to drag the info of the pic selected and the comments that come along with it (not included yet) but could use some advice on that too.

Thanks

 

Name: gewqrgf photo: uploads/EmptyTwo.png state: wfe

 

<!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=UTF-8" />
<title>What do you know about.......</title>
</head>

<body>
<?php
$hostname='.';
$username='.';
$password='.!';
$dbname='.';
$usertable='.';

mysql_connect('.', ''', ''!') or die(mysql_error());
mysql_select_db("'") or die(mysql_error());

$result = mysql_query("SELECT * FROM photo")
or die(mysql_error());  

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );


echo "Name: ".$row['name'];
echo " photo: ".$row['photopath'];
echo " state: ".$row['state'];
?>

<?php 
  
//$photopath = mysql_real_escape_string($_REQUEST['photpath']);
//$name = mysql_real_escape_string($_REQUEST['name']);
//$state = mysql_real_escape_string($_REQUEST['state']);

?>


</body>
</html>

Link to comment
Share on other sites

Well, you have to change a few things to make this work right.

 

Do you have an 'id' column (unique, auto_increment, primary) for your pictures? This is pretty much necessary.

 

Once you have that, populate the links in your gallery with 'viewpicture.php?id=12345', where 12345 is the image's ID.

 

Once you have that, you can easily select a single picture from your database to display it.

 

<!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=UTF-8" />
<title>What do you know about.......</title>
</head>

<body>
<?php
$hostname='.';
$username='.';
$password='.!';
$dbname='.';
$usertable='.';

mysql_connect('.', ''', ''!') or die(mysql_error());
mysql_select_db("'") or die(mysql_error());

if( is_numeric($_GET['id']) ) {
$result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = {$_GET['id']}");
	or die(mysql_error());  

	// store the record of the "example" table into $row
	$row = mysql_fetch_array( $result );


	echo "Name: ".$row['name'];
	echo " photo: ".$row['photopath'];
	echo " state: ".$row['state'];

} else {
echo 'BAD PHOTO ID';

?>

</body>
</html>

Link to comment
Share on other sites

each picture is uploaded by a user and each picture gets an id. Will this still work the same? Actually let me try it out. Also would this be the same way to deal with comments? Drop the comment system on the template page and just add another call for all comments associated with a pictures id?

 

Tried it and keep getting BAD PHOTO ID.

 

what do you mean "populate the links in your gallery with 'viewpicture.php?id=12345', where 12345 is the image's ID." Don't they already get assigned one when they are uploaded or is this something different?

 

Link to comment
Share on other sites

You'll get BAD PHOTO ID if $_GET['id'] isn't a number.

 

I used that to prevent users from injecting SQL into your script.

 

Made a mistake in my example as well

 

} else {
echo 'BAD PHOTO ID';

 

should be

 

} else
echo 'BAD PHOTO ID';

Link to comment
Share on other sites

here is a quick revise

<?php
$id = (int)$_GET['id'];
if( $id > 0 ) {
  $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error());
  // store the record of the "example" table into $row
  $row = mysql_fetch_array( $result );
  echo "Name: ".$row['name'];
  echo " photo: ".$row['photopath'];
  echo " state: ".$row['state'];
} else {
  echo 'BAD PHOTO ID';
}

Link to comment
Share on other sites

The only way you should be getting a BAD ID error is if

 

is_numeric( $_GET['id'] ) is false. You could try removing that check temporarily to see if it works... but I don't suggest putting it live without some form of sanitation

 

EDIT - MadTechie's revision should work just as well.

Link to comment
Share on other sites

Okay so we know the problem then,

id isn't being passed via the URL (or its not a number)

 

use the code below

<?php
$id = (int)$_GET['id'];
if( $id > 0 ) {
  $result = mysql_query("SELECT `name`, `photopath`, `state` FROM `photo` WHERE `id` = $id") or die(mysql_error());
  // store the record of the "example" table into $row
  $row = mysql_fetch_array( $result );
  echo "Name: ".$row['name'];
  echo " photo: ".$row['photopath'];
  echo " state: ".$row['state'];
} else {
  echo 'BAD PHOTO ID';
  echo "<BR />\n--------------------------------";
  var_dump($_GET);
  echo "<BR />\n--------------------------------";
}

and give us the results between the -----------------

if you get Array(0)

 

then we're need to see the form its being posted from.. or the href of the link used

either way you please confirm that the URL has the id

Link to comment
Share on other sites

Ok here's the result: BAD PHOTO ID

--------------------------------array(0) { }

--------------------------------

 

and here's the href:<a href="image_show.php"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a>

 

and this code is for the gallery where the photos are uploaded to then when clicked go to image_show page.

 

Thanks for sticking around guys.

 

 


<?php require_once('myconn.php'); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

$maxRows_Recordset1 = 40;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_myconn, $myconn);
$query_Recordset1 = "SELECT `name`, `photopath`, `state` FROM photo";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>

<div id="photos">
  <table border="">
  <?php $i=0; $numperpage=8; ?>
    <?php do { ?>
    <?php if ($i%$numperpage==0) echo "<tr>"; ?>
        <td align="center">
        
        <a href="image_show.php"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a>

<br/> 

<?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td>
<?php $i++; if ($i%$numperpage==0) echo "</tr>"; ?>

        
      
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
Share on other sites

Yep, id wasn't sent

 

 

Try this

See updates

 

//Added ID
$query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo";

 

     //uPDATED
      <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a>

 

full code

 

<?php require_once('myconn.php');

if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
    if (PHP_VERSION < 6) {
      $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;
  }
}

$maxRows_Recordset1 = 40;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_myconn, $myconn);
//Added ID
$query_Recordset1 = "SELECT `id`, `name`, `photopath`, `state` FROM photo";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $myconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<div id="photos">
  <table border="">
    <?php $i=0;
    $numperpage=8; ?>
    <?php do { ?>
      <?php if ($i%$numperpage==0) echo "<tr>"; ?>
    <td align="center">
      //uPDATED
      <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a>
      <br/>
<?php echo $row_Recordset1['name']; ?><br/> <?php echo $row_Recordset1['state']; ?></td>
      <?php $i++;
      if ($i%$numperpage==0) echo "</tr>"; ?>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
Share on other sites

are you storing your photos in a directory or only in your db

 

have them in a directory called uploads the saving the path in db.

 

heres what I got Madtechie

 

Name: iuhgu photo: uploads/Yourpartners state: asdfsg

 

its coming through and the url is ok: /image_show.php?id=34 but the no image only the path

Link to comment
Share on other sites

okay.. problem #1 sorted

Now

We need a little more details about the paths

 

So can you give up the url of the html file and a url of the images

 

for example

http://localhost/image_show.php?id=34

http://localhost/uploads/myimage.jpg

 

Now it seams the image filename is also missing so

try changing

 <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src=<?php echo $row_Recordset1['photopath'] ;?> height="200" width="200"/></a>

to (the WHOLE line)

 <a href="image_show.php?id=<?php echo $row_Recordset1['id'];?>"><img src="/<?php echo $row_Recordset1['photopath'].$row_Recordset1['name'] ;?>" height="200" width="200"/></a>

 

Link to comment
Share on other sites

 

So can you give up the url of the html file and a url of the images

 

 

no problem. Yourpartnerspartners.com/photo_list.php

                  Yourpartnerspartners.com/uploads/whatever.jpg                     

                Upload form: Yourpartnerspartners.com/upload_main.php

                (don't mind the styling)

 

 

Link to comment
Share on other sites

OKay the last update should show the image on the page with the link

 

Now update the photo line in the file image_show.php to

  echo " photo: <img src=\"/{$row['photopath']}{$row['name']}\" height=\"200px\" width=\"200px\" />";

 

EDIT:

i really don't see the point in this question

yeah what exactly are you storing in your photopath field...this should be fairly easy

Yeah fairly easy to guess!

Link to comment
Share on other sites

yeah what exactly are you storing in your photopath field...this should be fairly easy

 

the photopath field stores uploads/image.jpg, uploads/image2.png etc. I figured when called it would just go to the directory and grab the file. I don't like to store images on the db.

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.