tracy Posted December 13, 2006 Share Posted December 13, 2006 I can upload a file to the server and mysql table using phpno problemwhen I display the table using php, no photo, only photo nameany thoughts? here is the display code for this example...<?php include ("link.php"); if($query= mysql_query("SELECT * FROM inventory")) { $num = mysql_num_rows($query); }else { die('There was an error with the query:<br>'.mysql_error()); } if ($num == '0') { echo "Nothing Exist."; die(); } else { ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td><font face=Arial>Stock#</font> </td> <td><font face=Arial>Year</font> </td> <td><font face=Arial>Make</font> </td> <td><font face=Arial>Model</font> </td> <td><font face=Arial>Price</font> </td> <td><font face=Arial>Miles</font> </td> <td><font face=Arial>Photo</font> </td> </tr> <? while ($info = mysql_fetch_array($query)) { $stock = $info['stock']; $year = $info['year']; $make = $info['make']; $model = $info['model']; $price = $info['price']; $miles = $info['miles']; $photo1 = $info['photo1']; echo (" <tr> <td> <font face=Arial>$stock</font> </td> <td> <font face=Arial>$year</font> </td> <td> <font face=Arial>$make</font> </td> <td> <font face=Arial>$model</font> </td> <td> <font face=Arial>$price</font> </td> <td> <font face=Arial>$miles</font> </td> <td> <font face=Arial>$photo1</font> </td> </tr> "); } ?> </table> <? } ?> Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/ Share on other sites More sharing options...
papaface Posted December 13, 2006 Share Posted December 13, 2006 How are you inserting the photo into the database. You cant just insert it into the database, it has to be read and THEN inserted. e.g:[code] $filename = $_FILES["upload"]["name"]; $filetype = $_FILES["upload"]["type"]; $filesize = $_FILES["upload"]["size"]; $tmpname = $_FILES["upload"]["tmp_name"]; $open = fopen($tmpname,"r"); $file = fread($open, filesize($tmpname)); $file = addslashes($file); $addtodb = "insert into uploads (name,type,size,upload) values ('$filename','$filetype','$filesize','$file')";[/code] Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140375 Share on other sites More sharing options...
tracy Posted December 13, 2006 Author Share Posted December 13, 2006 I use this code to insert the file:<html><title>Add Vehicle Form</title><body><form action="insert.php" method="post"><table><tr><td>Stock Number:</td><td><input type="varchar" name="stock" /></td></tr><td>Year:</td><td><input type="tinyint" name="year" /></td></tr><td>Make:</td><td><input type="text" name="make" /></td></tr><td>Model:</td><td><input type="varchar" name="model" /></td></tr><td>Price:</td><td><input type="tinyint" name="price" /></td></tr><td>Miles:</td><td><input type="tinyint" name="miles" /></td></tr><td>Photo1:</td><td><input type="file" name="photo1" /></td></tr><input type="submit" /></form></body></html> Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140376 Share on other sites More sharing options...
Cagecrawler Posted December 13, 2006 Share Posted December 13, 2006 Presuming you want the photo where $photo1 is, and assuming that the database holds the link to the photo, this is what you need:<img src=$photo1 alt=$model>[code]<?phpecho ("<tr><td> <font face=Arial>".$stock."</font></td><td> <font face=Arial>".$year."</font></td><td> <font face=Arial>".$make."</font></td><td> <font face=Arial>".$model."</font></td><td> <font face=Arial>".$price."</font></td><td> <font face=Arial>".$miles."</font></td><td> <font face=Arial><img src=".$photo1." alt=".$model."></font></td></tr>"); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140378 Share on other sites More sharing options...
papaface Posted December 13, 2006 Share Posted December 13, 2006 ^^ correctAs for how you insert the file into the database - that form doesnt insert it. insert.php does. Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140379 Share on other sites More sharing options...
tracy Posted December 13, 2006 Author Share Posted December 13, 2006 Would you explain the 'database holds the link to the file' part? I thought the database would hold the photo file, much like it holds other data. I want to display using several sizes. Is there a better method?I guess to answer your question, yes, the photo1 cell holds the file I uploaded for the photo...thanks.[quote author=Cagecrawler link=topic=118457.msg484049#msg484049 date=1166017510]Presuming you want the photo where $photo1 is, and assuming that the database holds the link to the photo, this is what you need:<img src=$photo1 alt=$model>[code]<?phpecho ("<tr><td> <font face=Arial>".$stock."</font></td><td> <font face=Arial>".$year."</font></td><td> <font face=Arial>".$make."</font></td><td> <font face=Arial>".$model."</font></td><td> <font face=Arial>".$price."</font></td><td> <font face=Arial>".$miles."</font></td><td> <font face=Arial><img src=".$photo1." alt=".$model."></font></td></tr>"); ?>[/code][/quote] Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140382 Share on other sites More sharing options...
Cagecrawler Posted December 13, 2006 Share Posted December 13, 2006 If you post insert.php, it'll make it easier to confirm, but I assumed that when the photo was uploaded to a folder, the link to the photo was stored in the database, rather than the actual photo. I don't know of a way to store the actual photo in the database, but there may be. Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140388 Share on other sites More sharing options...
tracy Posted December 13, 2006 Author Share Posted December 13, 2006 I don't really have to store the photo in the database, and I think I'd be better off if I did not store it there, only the link. That's what I'm confused about. Where should I store the photo? Simply in a file called photos, for example? Then if it's in the same directory as the php code that 'calls' it, it works... Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140389 Share on other sites More sharing options...
Cagecrawler Posted December 13, 2006 Share Posted December 13, 2006 Yeh, a folder named photos would be simple enough. Link to comment https://forums.phpfreaks.com/topic/30494-photo-display-mysql-php/#findComment-140414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.