Phpmyadmin image chase

I have seen a few tutorials for storing and retrieving images in a database but I have so far been unable to get anything working. What I ideally want is to create a database with a couple of hundred images where users can input a search and the associated images will be displayed.

I can do this with text no problem but with images I have run into trouble and I’m not really sure why. - I am using phpmyadmin and dreamweaver cs3.

If anyone is kind and patient enough to coax me through it in simple terms I would be grateful beyond words.

create your database as though the images were located on flickr or facebook or something – all you store in the database is the url of the image

so your admin pages (to add images) and your search pages (to retrieve images) simply use the url instead of the actual image itself

with me so far?

now the only difference is that the images aren’t actually stored elsewhere, they’re stored on your web server, so the url is a relative url, not an absolute url out to the web

simple, eh?


no not really - can we start from the top? …just to make sure I’m not doing anything incredibly stupid…

In what format do I store the url in phpmyadmin and where do I put the url instead of the actual image in dreamweaver?

the format would be as a text column, typically VARCHAR(255)

how do you deal with the image’s title? the image’s owner? other image fields?

in your web app, they’d be on a form as form fields, and in phpmyadmin they’re just fields of the images table

just think of the url as another text field you need to store for each image

Basic file uploads:

from either of those scripts you get the final filename and it’s destination:

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

so you can add the path into your database table along with the image name. Then reference the image and builds th epath in yout page output

// ^^ ^ assuming query 
$rows = mysq;_fetch_assoc($sql);

echo '<img src="'. $rows['imagePath'] .'/'. $rows['imageName'] .'" />';

spikeZ - Thanks but no idea where I’m supposed to put any of that

r937 - 1) In dreamweaver on my results page I’m using the bindings to connect to the phpmyadmin database filtering my search. So the form fields are {rsdef3.search_name}, {rsdef3.definition}, {rsdef3.word_code} , not the actual image.

               2) So am I right in thinking that in phpmyadmin I must insert a new entry for each image or a new field for each image because I inserted a new field with url and when I attempted to test it in the bindings section of dreamweaver it came up with the following message:

MySQL Error#: 1064

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 ‘:// FROM ‘dictionary’ WHERE search_n’ at line 1

looks like some missing quotes

i’ve only used dreamweaver briefly – i have version 3, and i only ever used it to clean up the html produced by converting an RTF file, or to remove a column from the middle of an html table (try that, hand-coders!!)

but if you press F10 i believe you can still see source code, so have a look for the actual SQL that produced that error

ok I put speech marks on the URL in the new field on the phpmyadmin table and am now presented with this when I preview it on the web browser:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/stalkio/public_html/results4d.php on line 69

on line 69:

$query_rsdef3 = sprintf("SELECT search_name, definition, word_code, "" FROM `dictionary` WHERE search_name = &#37;s", GetSQLValueString($colname_rsdef3, "text"));

Any ideas anyone?

yes – always test your query outside of your php code first

open the SQL tab in phpmyadmin and paste the SELECT statement in there, substituting actual values for any php variables

SELECT search_name
     , definition
     , word_code
     , ""
  FROM `dictionary`
 WHERE search_name = [i]'some string value'[/i]

In phpmyadmin - doing what you said, it finds the right entry and displays the URL of the image (no image itself) but when I attempt to preview it in a browser it comes back with:

Parse error: syntax error, unexpected T_STRING in /home/stalkio/public_html/results4d.php on line 187

Line 186-190 in dreamweaver

mysql_select_db($database_Dictionary2, $Dictionary2);
$query_rsdef3 = sprintf("SELECT search_name, definition, word_code, "" FROM `dictionary` WHERE search_name = &#37;s", GetSQLValueString($colname_rsdef3, "text"));
$query_limit_rsdef3 = sprintf("%s LIMIT %d, %d", $query_rsdef3, $startRow_rsdef3, $maxRows_rsdef3);
$rsdef3 = mysql_query($query_limit_rsdef3, $Dictionary2) or die(mysql_error());
$row_rsdef3 = mysql_fetch_assoc($rsdef3);

With the culprit apparently being:

$query_rsdef3 = sprintf("SELECT search_name, definition, word_code, "" FROM `dictionary` WHERE search_name = %s", GetSQLValueString($colname_rsdef3, "text"));

I really appreciate this help by the way but what next?

you can’t use double quotes inside a string delimited by double quotes. change the double quotes around the url to single quotes.

ok great one problem resolved but the results page is only showing the url of the image not the actual image. How can I get to see the image itself?

when you place the information from the query results onto the page, from the sounds of it you are just placing the url text onto the page

what you need to do is insert the image url into an IMG tag, using the SRC= attribute

sorry where exactly do I input the <img src = “blahblah=image1” part? And should it just be addressed to the local folder or server?

where do you put the IMG tag? somewhere between <BODY> and </BODY>

and yes, the url will be the path to the image on the local server

This is how I used what you recommended:

Lines 257-263

   <?php do { ?>
            <td><?php echo $row_rsdef3['search_name']; ?></td>
            <td><?php echo $row_rsdef3['word_code']; ?></td>
			<td><?php echo "<img src=\\Images\\Horse1.jpg"view.php?file={$row_rsdef3['']}\\">";?></td>
          <?php } while ($row_rsdef3 = mysql_fetch_assoc($rsdef3)); ?>

But now I’m getting this error:

Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘;’ in /home/stalkio/public_html/results4d.php on line 261

What am I doing wrong now?

no idea, as i don’t do php at all (i can barely spell php) :slight_smile:

moving thread to php forum

make a new field in your database named img_filename
store the filename in this field

$format = "
SELECT search_name
     , definition
     , word_code
     , img_filename
  FROM `dictionary`
 WHERE search_name = %s

$sql = sprintf($format, GetSQLValueString($colname_rsdef3, "text"));
// always echo the sql to make its what you think when debugging
echo $sql;

$result = mysql_query($sql) or die('error, echo mysql_error(); for help');

while ($row_rsdef3 = mysql_fetch_assoc($result)) {
            &lt;td&gt;&lt;?php echo $row_rsdef3['search_name']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row_rsdef3['word_code']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;img src="url/path/to/image/dir/&lt;?php echo $row_rsdef3['img_filename']; ?&gt;"&gt;&lt;/td&gt;

crmalibu - that is exactly what I needed. Success and jubilation…you rule…stereo!!