Jump to content
Larry Ullman's Book Forums

Ch19 - Adding Product's Picture To The Database (Mysql) Row Rather Than Move To The Uploads Folder


Recommended Posts

Hi,

 

I started to implement the last chapter of the book (chapter-19 - e-commerce). Everything was good, till I found that I cannot write or move any file to the server drive, then I decided to add the product's picture to MySQL like other product information. However, I encountered errors and I could not add the product's info to MySQL. I want to know about the changes which I should make to do so.

 

 

Thank you

Link to post
Share on other sites

Um...off the top of my head...you'll need to move the image files to an accessible directory within web, and give each image a unique name. Then you'll need to manually insert the image information into the MySQL table. Then you'll need to just edit the product script to just create tags that link directly to the image file, not go through view_image.php. 

 

That's what I think you need to do off the top of my head. 

Link to post
Share on other sites

Hi,

 

First, I would appreciated for your reply. I made some of the changes which you mentioned, however, I encountered error again in some of the script syntax and I think I need your help again.

 
 
// Display each record:
echo "\t<tr>
<td align=\"left\"><a href=\"browse_prints.php?aid={$row['artist_id']}\">{$row['artist']}</a></td>
<td align=\"left\"><a href=\"view_print.php?pid={$row['print_id']}\">{$row['print_name']}</a></td>
<td align=\"left\">{$row['description']}</td>
<td align=\"right\">\${$row['price']}</td>
<td align=\"right\">//\${$row['image_name']}
if ($image = @getimagesize ("/images/$pid")) {
echo "<div align=\"center\"><img src=\"images?image=$pid&name=" . urlencode($row['image_name']) . "\" $image[3] alt=\"{$row['print_name']}\" /></div>\n";
} else {
echo "<div align=\"center\">No image available.</div>\n"; 
}
</td> 
<a href=\"add_cart.php?pid=$pid\">Add to Cart</a>
</tr>\n";
 
} // End of while loop.

 

 

Thank you again,

 

 

Mathew

Link to post
Share on other sites

It would help if you said what the actual error is and what steps you took up to that point. But if you followed my instructions, you'd use the image name itself in your tag, as you would any other image in HTML.

Link to post
Share on other sites

Hello,

 

There's a typo in the line you highlighted in red: you forgot the concatenation dots around $image[3]:

 

 

echo "<div align=\"center\"><img src=\"images?image=$pid&name=" . urlencode($row['image_name']) . "\" . $image[3] . alt=\"{$row['print_name']}\" /></div>\n";
 
I hope this helps,
 
Emilie
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...