By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

Another mySQL/picture problem

P: 2

I have a problem and for the life of me cannot figure out the problem. I inherited the PHP/mySQL code from a friend which did no documentation whatsoever. I do not know how this happened but it did.

My problem is with displaying images correctly. The images are in a table stored in a BLOB type. I now know that is bad but I really do not want to redo this if I can avoid it as there are a lot of images already stored with more being added almost daily.

So, the details of the problem go like this...

A user goes to a page to look up an image by either ID number or name. The submit button passes it to a php that uses this information to pull the image from the database and the image is displayed. Users sometime need to print the image for paper records. So, the user hits the print button in the web browser and the image prints. Up until this point everything works correctly. Any image you search for comes up. The proble is in the printing. It doesn't matter which image you search for and try to print the only image that prints is the first one in the database. Even when using the print preview button the only image that shows up is the first image. I have looked at the code and it looks good. But I am no expert in PHP and have no formal instruction on it; just what I have acquired from my own learning. So, I come to experts to see if I can get help.
The search form...
Expand|Select|Wrap|Line Numbers
  1. <h2>Search For Card</h2>
  2. <form action="viewCard2.php" method="post" target="_blank">
  3. Last 4 Digits of SSN: <input name=socsec maxlength="4" /><br>OR<br>
  4. Last Name: <input name="personname"><br><input type=submit value="View Card" /></form><br>
  5. (Card opens in new window.  If window is blank, no card found.)
And the results...
Expand|Select|Wrap|Line Numbers
  1. $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('WARNING! YOU ARE NOT LOGGED IN.  PLEASE RETURN TO MAIN PAGE AND TRY AGAIN WITH YOUR LOGIN INFORMATION');
  2. mysql_select_db($dbname,$conn); 
  3. $id = $_POST['socsec'];
  4. if($id=='') {
  5.         $query = "SELECT Image, SSN, Type, Size FROM Images WHERE Name LIKE '%$personname'";
  6. }
  7. else if($personname=='') {
  8.    $query = "SELECT Image, SSN, Type, Size FROM Images   WHERE SSN LIKE '%$id'";
  9. }
  10. else {
  11.    $query = "SELECT Image, SSN, Type, Size FROM Images WHERE SSN LIKE '%$id'";
  12. }
  13. $result = mysql_query($query) or die('Error, query failed');
  14. list($name, $soc, $type, $size) = mysql_fetch_array($result);
  15. header('Content-length: ' .$size);
  16. header('Content-type: ' .$type);
  17. echo $name;
  18. if($name=='') {
  19. echo "Sorry, no card found for $id $personname";
This is just the important search and results part. There is other code that pertains to the usual connections and stuff. Unless, of course, there is an off chance that this problem is related to the session that is used throughout the entire website. But I do not think that is the problem.
Feb 10 '12 #1
Share this Question
Share on Google+
3 Replies

P: 23
why dont you store the images in a directory and save their locations or urls in a simple varchar mysql table i think this will help reduce a lot of work for you.

As for the script i have it already do you need?
Feb 11 '12 #2

P: 2
That would be great. This one problem has been driving me nuts for three days now. Anything to help me would be awesome!
Feb 11 '12 #3

P: 23
need a zip or should i post it here now??
Feb 12 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.