Closed Thread
Page 9 of 22 FirstFirst ... 789101119 ... LastLast
Results 81 to 90 of 214

Thread: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

  1. #81
    Jan
    Jan is offline Newbie
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Thanks. I now made 2 very basic pages with nothing in except this:
    show.php:
    Code:
     
    <?php
    include ("inc_connect_dbase.php"); 
    
    $id=$_GET['id'];
    
    if(!isset($id) OR empty($id){
    	die("Select image first");
    }else{
    
    $query=myql_query("SELECT * FROM temp WHERE id='".$id."' ");
    $row=mysql_fetch_array($query);
    $content=$row['image'];
    $type=$row['type'];
    
    header('Content-type: image/jpeg');
    echo $content;
    
    ?>
    again.html:
    Code:
    <html>
    <body>
    <img src="show.php?id=1" />
    </body>
    </html>
    All I get now is the 'red cross' as in: no picture.
    I hope you can tell what's wrong with me... Thanks again!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #82
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    You haven't created an image in your code. What about imagecreate and all the other gd functions?

  4. #83
    Jaan Guest

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Naw dude..

    Code:
    header('Content-type: image/jpeg'); 
    this does the work.. but umm..

    What to you do with this line?
    Code:
    $type=$row['type']; 

  5. #84
    Jan
    Jan is offline Newbie
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi,

    I'm not doing anything with that line right now, I put it there cause I wanted to set the Content-type with that dynamically.
    Now, it's not doing anything, deleting it doesn't make a difference either.
    Still don't know what's going wrong..

  6. #85
    Jaan Guest

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Try this:

    Code:
    <?php
    include ("inc_connect_dbase.php"); 

    $id $_GET['id'];

    if(!isset(
    $id) || empty($id){
        die(
    "Select image first");
    }else{

    $query myql_query("SELECT * FROM temp WHERE id='".$id."' ") or die(mysql_error());
    $row mysql_fetch_array($query);
    $content $row['image'];

    header('Content-type: image/jpeg');
    echo 
    $content;

    ?>
    If there are any errors now.. tell me these

  7. #86
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    in displayimage.php the assumed the pic_id is 3...and its working fiine if the number after pic_id is constant..how about making a dynamic link which if i click the text, the selected image will appear on a different page.. im having hard time displaying the $id

    if i use this

    <img src= "displayimage.php?pic_id=CONSTANT VALUE" />
    its getting the image on the database.. working fine..

    <img src= "displayimage.php?pic_id=$id" />

    if i use this after pic_id= <? ['$id'] ?> nothing happens

    i just want to know how to call the pic id...
    i dont know what to do...

    any help? please...
    thanks in advance
    Last edited by hardinera; 07-28-2009 at 11:14 PM.

  8. #87
    Jan
    Jan is offline Newbie
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Thanks Jaan, but no errors, strangely.
    Found there was a ) missing after empty($id), but it didn't make a difference.

    Thought maybe it had to do with my server settings(?) so uploaded the files to a different server. This also didn't work but when I tried opening just the show.php file in the browser I got a parse error:
    Parse error: parse error, unexpected $ in /..../show.php on line 16
    Line 16 is the line with just ?> on it

    My table looks like this:
    id - name - size - type - image
    1 - lb.jpg - 6032 - image/jpeg - [BLOB - 5.9 KiB]

  9. #88
    Jan
    Jan is offline Newbie
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Dude! my god that was stupid of me!
    I didn't put the closing } at the end!
    It's working now! thanks for the help!

  10. #89
    Jan
    Jan is offline Newbie
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    And for Hardinera, try this:

    Code:
    <?php echo("<img src=\"show.php?id=$id\" />"); ?>
    or:
    Code:
    <img src="show.php?id=<?php echo($id);?>" />
    assuming that you have set $id somewhere

  11. #90
    xmodpt's Avatar
    xmodpt is offline Newbie
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hello all

    I am new to PHP and probably a slow learner.

    I have to thank you all for all the help... this really works ( TESTE OK ).

    My problem ( theory):

    - Login/Register form Working ok
    - Pic Upload ( from here ) working ok

    I have a Login/Register app working and i need to attache a "image" per user.
    When the user registers, he upload one "image".
    This Image will pop once the user logs in ( for exemple: his photo )

    My Problem ( practical )

    Together ---- nothing works **** hope you guys can help me

    This a modifeid version of you Add.php (register-form.php)

    Code:
    <?php
        session_start
    ();
    ?>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Login Form</title>
    <link href="loginmodule.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php
        
    if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >) {
            echo 
    '<ul class="err">';
            foreach(
    $_SESSION['ERRMSG_ARR'] as $msg) {
                echo 
    '<li>',$msg,'</li>'
            }
            echo 
    '</ul>';
            unset(
    $_SESSION['ERRMSG_ARR']);
        }

    ?>

    <form id="loginForm" name="loginForm" method="post" action="register-exec.php">
      <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr>
          <th>First Name </th>
          <td><input name="fname" type="text" class="textfield" id="fname" /></td>
        </tr>
        <tr>
          <th>Last Name </th>
          <td><input name="lname" type="text" class="textfield" id="lname" /></td>
        </tr>
        <tr>
          <th width="124">Login</th>
          <td width="168"><input name="login" type="text" class="textfield" id="login" /></td>
        </tr>
        <tr>
          <th>&nbsp;</th>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th>Password</th>
          <td><input name="password" type="password" class="textfield" id="password" /></td>
        </tr>
        <tr>
          <th>Confirm Password </th>
          <td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input name="signature" accept="image/jpeg" type="file" id="signature" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="Submit" value="Register" /></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    This is a modifeid version of your Insert.php (register-exec.php)

    Code:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Include database connection details
        
    require_once('config.php');
        
        
    //Array to store validation errors
        
    $errmsg_arr = array();
        
        
    //Validation error flag
        
    $errflag false;
        
        
    //Connect to mysql server
        
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
        
    //Select database
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    "Unable to select database");
        }
        
        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
        
        
    //Sanitize the POST values
        
    $fname clean($_POST['fname']);
        
    $lname clean($_POST['lname']);
        
    $login clean($_POST['login']);
        
    $password clean($_POST['password']);
        
    $cpassword clean($_POST['cpassword']);
        
    $signature clean($_FILES['signature']);
        
        
    //Input Validations
        
    if($fname == '') {
            
    $errmsg_arr[] = 'First name missing';
            
    $errflag true;
        }
        if(
    $lname == '') {
            
    $errmsg_arr[] = 'Last name missing';
            
    $errflag true;
        }
        if(
    $login == '') {
            
    $errmsg_arr[] = 'Login ID missing';
            
    $errflag true;
        }
        if(
    $password == '') {
            
    $errmsg_arr[] = 'Password missing';
            
    $errflag true;
        }
        if(
    $cpassword == '') {
            
    $errmsg_arr[] = 'Confirm password missing';
            
    $errflag true;
        }

        if( 
    strcmp($password$cpassword) != ) {
            
    $errmsg_arr[] = 'Passwords do not match';
            
    $errflag true;
        }
    //    if($signature == '') {
    //        $errmsg_arr[] = 'No signature file selected';
    //        $errflag = true;
    //    }
        
        //Check for duplicate login ID
        
    if($login != '') {
            
    $qry "SELECT * FROM members WHERE login='$login'";
            
    $result mysql_query($qry);
            if(
    $result) {
                if(
    mysql_num_rows($result) > 0) {
                    
    $errmsg_arr[] = 'Login ID already in use';
                    
    $errflag true;
                }
                @
    mysql_free_result($result);
            }
            else {
                die(
    "Query failed");
            }
        }
        
        
    //If there are input validations, redirect back to the registration form
        
    if($errflag) {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            
    session_write_close();
            
    header("location: register-form.php");
            exit();
        }

        
    //Create INSERT query
        
    $qry "INSERT INTO members(firstname, lastname, login, passwd, signature) VALUES('$fname','$lname','$login','".md5($_POST['password'])."','$signature')";
        
    $result = @mysql_query($qry);
        
        
        
    //Check whether the query was successful or not
        
    if($result) {
            
    header("location: register-success.php");
            exit();
        }else {
            die(
    "Query failed");
        }
    ?>
    My problem is, as it is the register go ok but no image is uploaded.

    Can anyone help a NooooB

    Thank u all in advance
    Xmodpt

Closed Thread
Page 9 of 22 FirstFirst ... 789101119 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2011, 11:29 AM
  2. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 47
    Last Post: 01-04-2011, 08:37 PM
  3. Beginner Storing images in XML file - Part II - Displaying image
    By Jaan in forum PHP Tutorials
    Replies: 6
    Last Post: 01-04-2011, 08:35 PM
  4. display images sequentially using PHP and MySQL
    By jhanjon in forum PHP Development
    Replies: 2
    Last Post: 10-08-2009, 12:11 PM
  5. Replies: 2
    Last Post: 07-16-2009, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts