Jump to content

Having troubles - image does not show up.


sjones

Recommended Posts

Hello, I am trying to write a script that will allow the user to view vendors, select their name, hit the view button and see their image. I have everything done accept the image does'nt show up in the browser.

[a href=\"http://www.uswebproducts.com/country_savings/view_coupon.php\" target=\"_blank\"]Click here to view[/a]

The script is below, If someone can tell me where I went wrong, I would appreciate it.

<?php
echo "Testing the view_coupon.php page!";
include ('connections/mysql_connect.php');
if (!isset($_POST['submit'])) {
echo "<form method='post' action='view_coupon.php'>
<select name='vendor_id'>
<option>- Please select one -</option>\n";
$qry = mysql_query("SELECT * FROM vendors;");
while($rows = mysql_fetch_assoc($qry)) {
echo "<option value='".$rows['vendor_id']."'>".$rows['vendor_name']."</option>\n";
}
echo "</select>
<input name='submit' type='submit' value='View'>
</form>";
}else{

if (isset($_POST['submit'])) {
$image_query ="SELECT file_name FROM uploads
WHERE uploads.vendor_id = ('".$_POST['vendor_id']."');";
$result = mysql_query($image_query);
$record = mysql_fetch_row($result);
echo "<table align='center' width='90%'>
<tr>
<td><img src='http://uswebproducts.com/country_savings/uploads/$record'>
</td>
</tr>
</table>";
}
}

?>
Link to comment
https://forums.phpfreaks.com/topic/4379-having-troubles-image-does-not-show-up/
Share on other sites

[!--quoteo(post=352656:date=Mar 7 2006, 05:33 PM:name=sjones)--][div class=\'quotetop\']QUOTE(sjones @ Mar 7 2006, 05:33 PM) [snapback]352656[/snapback][/div][div class=\'quotemain\'][!--quotec--]
$record = mysql_fetch_row($result);
//...
<td><img src='http://uswebproducts.com/country_savings/uploads/$record'>
[/quote]
mysql_fetch_row returns an array, that's why the image displayed is:
"http://uswebproducts.com/country_savings/uploads/Array"
Use $record[0...1...2...etc] according to field order

It would be better to use mysql_fetch_array or mysql_fetch_assoc in your case.
This is the correction that I came up with it works very well. Thanks for the reply

else{
if (isset($_POST['submit'])) {
$image_query ="SELECT file_name FROM uploads
WHERE uploads.vendor_id = ('".$_POST['vendor_id']."');";
$result = mysql_query($image_query);
while ($record = mysql_fetch_row($result)) {
for ($i = 0; $i < count($record); $i++) {
echo "<table align='center' width='90%'>
<tr>
<td><img src='http://uswebproducts.com/country_savings/uploads/$record[$i]'>
</td>
</tr>
</table>";
}
}
}
}

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.