code for retrieving image in database.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul NIcolai Sunga
    New Member
    • Mar 2008
    • 43

    code for retrieving image in database.

    is this applicable?


    Code:
     
    <?php
    $query = mysqli_query($Link, "SELECT * from Registration_form where last_insert_id(form_no)" );
     while($row = mysqli_fetch_array($query)){
    $picture = $row['picture'];
    }
    ?>

    thanks...:)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what does the manual say?

    Comment

    • Canabeez
      New Member
      • Jul 2009
      • 126

      #3
      Nope...

      You have a few mistakes in your code, (first) the $Link variable should go as a second parameter; (second) last_insert_id( ) cannot be used in SELECT, only in INSERT; (third) there's no point in while if you want a single row.

      Here, if your form_no is auto_increment then this code should work:
      [code=php]
      $query = mysql_query("SE LECT `picture` FROM `Registration_f orm` ORDER BY `form_no` DESC LIMIT 1;", $Link);

      if($row = mysql_fetch_row ($query))
      {
      $picture = $row['picture'];
      }[/code]

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by Canabeez
        You have a few mistakes in your code, (first) the $Link variable should go as a second parameter;
        sorry to correct you here, mysqli_* indeed uses the connection instance as first parameter (in contrast to mysql_*)

        although if I’d be using MySQLi I’d rather use the object oriented style.

        Comment

        • Canabeez
          New Member
          • Jul 2009
          • 126

          #5
          Originally posted by Dormilich
          sorry to correct you here, mysqli_* indeed uses the connection instance as first parameter (in contrast to mysql_*)

          although if I’d be using MySQLi I’d rather use the object oriented style.
          Thanks... you're right... didn't mention the mysqli, didn't even think that anyone really uses that... I think the rest is fine...

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by Canabeez
            didn't even think that anyone really uses that...
            although I find MySQLi much more capable than mysql_*. guess most people are already accustomed to mysql_* and don’t want to change for the better…

            Comment

            • Canabeez
              New Member
              • Jul 2009
              • 126

              #7
              not only accustomed, think of all the code, rewrite all that?! hell no... only I have something like 50,000 lines using mysql_.

              Comment

              • Paul NIcolai Sunga
                New Member
                • Mar 2008
                • 43

                #8
                thanks for correcting my errors in my codes..thanks a lot.. it is a big help for me..

                Comment

                • Paul NIcolai Sunga
                  New Member
                  • Mar 2008
                  • 43

                  #9
                  whats this warning?


                  Warning: mysql_query() expects parameter 2 to be resource, object given in C:\wamp\www\dfd fdd.php on line 16

                  Warning: mysql_fetch_row () expects parameter 1 to be resource, null given in C:\wamp\www\dfd fdd.php on line 18

                  Comment

                  • Paul NIcolai Sunga
                    New Member
                    • Mar 2008
                    • 43

                    #10
                    Code:
                    <?Php   
                    error_reporting (E_ALL ^ E_NOTICE);
                    
                    $Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
                    			if (!$Link)
                      			{
                      			trigger_error("Could not connect", E_USER_ERROR );
                      			}
                    $query = mysqli_query($Link, "SELECT picture FROM Registration_form ORDER BY form_no DESC LIMIT 1" );
                     
                       if($row = mysqli_fetch_row($query))
                       {
                         $picture1 = $row['picture'];
                       }
                       
                       ?>
                    
                    <table width="200" border="1">
                      <tr>
                    <td><input name="pix" type="image" value="<?Php  error_reporting (E_ALL ^ E_NOTICE);  echo $picture; ?>"/></td>
                    </tr>
                    </table>

                    is this correct? the picture is not appearing..

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      Originally posted by Paul NIcolai Sunga
                      the picture is not appearing..
                      of course. the image is referenced using the "src" attribute (which btw is a file name). It's completely useless to try inserting the image data (binary type) into html sorce code (text type).

                      see also Atli's article

                      Comment

                      Working...