3 Replies - 341 Views - Last Post: 18 May 2014 - 02:38 AM Rate Topic: -----

#1 lwithwma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 14

Uploading Profile Picture Problem

Posted 18 May 2014 - 12:13 AM

Uploading profile picture problem
Which shows Fatal error: Call to a member function query() on a non-object in /public_html/upload.php on line 3 please help me out my friends :helpsmilie:/>/>/>

Please See the following code of action page image.php

<?php
$user=$_SESSION['user'];
$db=new mysqli('','','','');
if($db->connect_errno){
echo $db->connect_error;}
$pull="select * from userImage  where user='$user'";

$allowedExts = array("jpg", "jpeg", "gif", "png","JPG");
$extension = @end(explode(".", $_FILES["file"]["name"]));
if(isset($_POST['pupload'])){
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo '<div class="plus">';
    echo "Uploaded Successully";
    echo '</div>';
     
    echo"<br/><b><u>Image Details</u></b><br/>";
   
    echo "Name: " . $_FILES["file"]["name"] . "<br/>";
    echo "Type: " . $_FILES["file"]["type"] . "<br/>";
    echo "Size: " . ceil(($_FILES["file"]["size"] / 1024)) . " KB";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      unlink("upload/" . $_FILES["file"]["name"]);
      }
    else
      {
          $pic=$_FILES["file"]["name"];
            $conv=explode(".",$pic);
            $ext=$conv['1'];

      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/". $user.".".$ext);
      echo "Stored in as: " . "upload/" . $user.".".$ext;
      $url=$user.".".$ext;
   
      $query="update userImage set url='$url', lastUpload=now() where user='$user'";
      if($upl=$db->query($query)){
          echo "<br/>Saved to Database successfully";
              }
      }
    }
  }
else
  }
  echo "File Size Limit Crossed 200 KB Use Picture Size less than 200 KB";

  }
}
?>



Here is the code of uploading page upload.php
<form action="image.php" method="post" enctype="multipart/form-data">   
  <?php
    $res=$db->query($pull);
    $pics=$res->fetch_assoc();
    echo '<div class="imgLow">';
    echo "<img src='upload/$pics[url]' alt='profile picture' width='80' height='64'   class='doubleborder'/></div>";
   
    ?>
   
    <input type="file" name="file" />
    <input type="submit" name="pupload" class="button" value="Upload"/>
  
</form>


Kindly help me :helpsmilie:/>/>/> :helpsmilie:/>/>/>

Is This A Good Question/Topic? 0
  • +

Replies To: Uploading Profile Picture Problem

#2 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 39
  • View blog
  • Posts: 898
  • Joined: 06-July 13

Re: Uploading Profile Picture Problem

Posted 18 May 2014 - 12:22 AM

Quote

Fatal error: Call to a member function query()
means your db object is non-existant. You should make sure that the link to it in the external file is correct, or before the query executed.
Was This Post Helpful? 0
  • +
  • -

#3 lwithwma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 14

Re: Uploading Profile Picture Problem

Posted 18 May 2014 - 12:30 AM

Thankyou friend to let me know this. Gonna Checkout. :)
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: Uploading Profile Picture Problem

Posted 18 May 2014 - 02:38 AM

another problem are lines #4-5. while you’re checking for an error (which is a good thing), you don’t do anything (except a print out) if an error actually occurs.

as for the problem, there is no source to see where you create the $db variable in upload.php. both image.php and upload.php are totally independend PHP scripts, what you do in one script doesn’t affect the other in any way (well, always based upon what is posted here, anyways).

This post has been edited by Dormilich: 18 May 2014 - 02:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1