i tried atli's manual and the picture is not appearing?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #31
    Originally posted by Paul NIcolai Sunga
    the issue about the displaying picture from mysql is still unsolved..
    so, did you verify that the picture is in the DB (and not corrupted)?

    Comment

    • Paul NIcolai Sunga
      New Member
      • Mar 2008
      • 43

      #32
      yeah.. in atli's code there were files in the DB but when i tried to check my own, there was no files.. im going to start again.. hope i can do it.. i'll try to fix the codes.. the insert query maybe has an error..
      here's now my code:
      Code:
       
      <?php 
      error_reporting (E_ALL ^ E_NOTICE);
      
      $pid = base64_decode($_GET['id']);
      
      if(isset($_FILES['uploaded_file']))
      {
      if($_FILES['uploaded_file']['error'] == 0)
      	{$Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
      	if(mysqli_connect_errno()){
      		die("Mysql connection failed:".mysqli_connect_errno());
      		}
      		$name = mysqli_real_escape_string($Link, $_FILES['uploaded_file']['name']);
      		$data = mysqli_real_escape_string($Link, file_get_contents($_FILES ['uploaded_file']['tmp_name']));
      		
      		$query = "INSERT INTO pix(pid, title, imgdata) values('$pid', '$name', '$data')";
      		
      		$result = mysqli_query($Link, $query);
      		if($result)
      		{
      $asd = "Succes! YOur file was successfully added!";
      $alert = base64_encode($asd);
      header("Location:registration.php?alert=$alert");
      exit();
      		}
      		else
      		{
      		$asd = "Error! An error occurred while the file was being uploaded.
      		Error code:".$_FILES['uploaded_file']['error'];
      $alert = base64_encode($asd);
      header("Location:picul.php?alert=$alert");
      exit();
      		}
      		mysqli_close($Link);
      }
      it is not inserting..

      Comment

      • Paul NIcolai Sunga
        New Member
        • Mar 2008
        • 43

        #33
        Originally posted by Paul NIcolai Sunga
        yeah.. in atli's code there were files in the DB but when i tried to check my own, there was no files.. im going to start again.. hope i can do it.. i'll try to fix the codes.. the insert query maybe has an error..
        here's now my code:
        Code:
         
        <?php 
        error_reporting (E_ALL ^ E_NOTICE);
        
        $pid = base64_decode($_GET['id']);
        
        if(isset($_FILES['uploaded_file']))
        {
        if($_FILES['uploaded_file']['error'] == 0)
        	{$Link = mysqli_connect("localhost","root","tupi", "amyak_maleh");
        	if(mysqli_connect_errno()){
        		die("Mysql connection failed:".mysqli_connect_errno());
        		}
        		$name = mysqli_real_escape_string($Link, $_FILES['uploaded_file']['name']);
        		$data = mysqli_real_escape_string($Link, file_get_contents($_FILES ['uploaded_file']['tmp_name']));
        		
        		$query = "INSERT INTO pix(pid, title, imgdata) values('$pid', '$name', '$data')";
        		
        		$result = mysqli_query($Link, $query);
        		if($result)
        		{
        $asd = "Succes! YOur file was successfully added!";
        $alert = base64_encode($asd);
        header("Location:registration.php?alert=$alert");
        exit();
        		}
        		else
        		{
        		$asd = "Error! An error occurred while the file was being uploaded.
        		Error code:".$_FILES['uploaded_file']['error'];
        $alert = base64_encode($asd);
        header("Location:picul.php?alert=$alert");
        exit();
        		}
        		mysqli_close($Link);
        }
        it is not inserting..
        with this code the data has inserted.. but now im having a problem retrieving the photo..

        Comment

        • Paul NIcolai Sunga
          New Member
          • Mar 2008
          • 43

          #34
          i used this:
          Code:
          <input name="image" type="image" src="asdf.php?imgid=<?Php echo $form_no; ?>" width="110" height="100"/>
          asdf.php where the image come from.
          Code:
          error_reporting (E_ALL ^ E_NOTICE);
          
          $id = $_GET['imgid'];
          
          $Link = mysqli_connect("localhost","root","***", "***");
          			if (!$Link)
            			{
            			trigger_error("Could not connect", E_USER_ERROR );
            			}
          if(!isset($id) || empty($id)){
          die("Please select your image!");
          }else{
          
          $query = mysqli_query($Link, "SELECT * FROM pix WHERE pid='$id' ");
          $row = mysqli_fetch_assoc($query);
          $content = $row['imgdata'];
          
          header('Content-type: image/jpg');
          echo $content;
          
          }
          and i tried this one: it still not showing:
          Code:
            header('Content-Type: image/jpeg');
              $id = $_GET['imgid'];
             $id = isset($_REQUEST['imgid']) ? $_REQUEST['imgid'] : false;
              
             if($id)
              {
                $Link = mysqli_connect("localhost","root","***", "***");
                if(mysqli_connect_errno())
                {
                   die("Mysql connection failed:".mysqli_connect_errno());
              }
              
               $result = mysqli_query($Link, "SELECT imgdata from pix where pid = '$id' ");
             
                if(is_resource($result))
                {
                   $row = mysql_fetch_row($result);
          		  header('Content-Type: image/jpeg');
                  echo $row['imgdata'];
          		
                }
            }
          the photo is not showing..which do you think the good code should i use and enhance? so that i will not get confused...


          thanks a lot...
          Last edited by Dormilich; Aug 13 '09, 03:58 AM. Reason: removed password

          Comment

          • Paul NIcolai Sunga
            New Member
            • Mar 2008
            • 43

            #35
            help. which code should i use?

            Comment

            Working...