2016-10-14 31 views
-2

我知道這可能看起來像一個重複的問題。看過不同的問題和答案,但很難得到結果。所以基本上我的編輯配置文件工作得很好,在我決定有更多的領域和仍然領域以某種方式造成問題之前。所以我得到這個錯誤努力調試成員函數bind_param()

Fatal error: Call to a member function bind_param() on boolean.

我要去告訴你下面

 <?php 

    // start session 
    session_start(); 

    error_reporting(E_ALL); ini_set('display_errors', 1); 

    // i user is not log in redirect back to index 
    if(!isset($_SESSION['user_type'])){ 
     header('Location: index.php'); 
    } 

    // include data based connection config 
    include_once('include/connection.php'); 

    // incluude header ttile page 
    $title = "Edit User Profile"; 

    // set user session variables 
    $userId = $_SESSION['user_id']; 
    //$userName = $_SESSION['user_name']; 
    $temp = $_SESSION['user_name']; 

    // if user update the data 
     if(isset($_POST['update'])){     


       ///////////////////// USER PROFILE IMAGE 
       // instantiate user profile image 
      $Destination = 'userfiles/avatars'; 
      if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name'])){ 
       $NewImageName = 'default.png'; 
       move_uploaded_file($_FILES['ImageFile']['tmp_name'], "$Destination/$NewImageName"); 
      } 
      else{ 
       $RandomNum = rand(0, 9999999999); 
       $ImageName = str_replace(' ','-',strtolower($_FILES['ImageFile']['name'])); 
       $ImageType = $_FILES['ImageFile']['type']; 
       $ImageExt = substr($ImageName, strrpos($ImageName, '.')); 
       $ImageExt = str_replace('.','',$ImageExt); 
       $ImageName = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName); 
       $NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt; 
       move_uploaded_file($_FILES['ImageFile']['tmp_name'], "$Destination/$NewImageName"); 
      } 


     /***** Multiple query ******/ 


        $firstname = trim($_POST['firstname']); 
        $lastname = trim($_POST['lastname']); 
        $email = trim($_POST['email']); 
        $user_name = trim($_POST['user_name']); 
        $profession = trim($_POST['profession']); 
        $phone = trim($_POST['phone']); 
         $postcode = trim($_POST['postcode']); 
        $address = trim($_POST['address']); 
        $bio = trim($_POST['bio']); 
        $dob = trim($_POST['dob']); 
        $gender = trim($_POST['gender']); 
        $country = trim($_POST['country']); 

    if(!($stmt = $con->prepare("SELECT * FROM user WHERE user_name = ?"))){ 
     die("Prepare failed: (" . $con->errno . ") " . $con->error); 
    } 
    if(!$stmt->bind_param('s', $temp)){ 
     die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error); 
    } 
    if($stmt->execute()){ 
     $stmt->store_result(); 
     $num_rows = $stmt->num_rows; 
     $stmt->close(); 

     if($num_rows){ 
      if(!empty($_FILES['ImageFile']['name'])){ 
       if(!($stmt = $con->prepare("UPDATE user SET avatar = ? WHERE user_name = ?"))){ 
        die("Prepare failed: (" . $con->errno . ") " . $con->error); 
       } 
       if(!$stmt->bind_param('ss', $NewImageName, $temp)){ 
        die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error); 
       } 
       if($stmt->execute()){ 
        $stmt->close(); 
        header("location:edit-profile.php?user_name=" . $temp); 
        exit(); 
       }else{ 
        die("Execute failed: (" . $stmt->errno . ") " . $stmt->error); 
       } 
      } 
     }else{ 
      if(!($stmt = $con->prepare("INSERT INTO user (avatar) VALUES (?)"))){ 
       die("Prepare failed: (" . $con->errno . ") " . $con->error); 
      } 
      if(!$stmt->bind_param('s', $NewImageName)){ 
       die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error); 
      } 
      if($stmt->execute()){ 
       $stmt->close(); 
       header("location:edit-profile.php?user_name=" . $temp); 
       exit(); 
      }else{ 
       die("Execute failed: (" . $stmt->errno . ") " . $stmt->error); 
      } 
     } 
    }else{ 
     die("Execute failed: (" . $stmt->errno . ") " . $stmt->error); 
    } 



    // ************* UPDATE PROFILE INFORMATION ************************// 
    if(!($stmt = $con->prepare("UPDATE user SET firstname = ?, lastname = ?, skills = ?, profession = ?, 
    user_name = ?, phone = ?, address = ?, email = ?, bio = ?, 
    gender = ?, dob = ?, country = ? WHERE id = ?"))) { 
     echo "Prepare failed: (" . $con->errno . ")" . $con->error; 
    } 
    if(!$stmt->bind_param('sssssissssssi', $firstname, $lastname, $skills, $profession, 
         $user_name, $phone, $address, $email, $bio, 
         $gender, $dob, $country, $userId)){ 
    echo "Binding paramaters failed:(" . $stmt->errno . ")" . $stmt->error; 
      } 
    if(!$stmt->execute()){ 
      echo "Execute failed: (" . $stmt->errno .")" . $stmt->error; 
      } 


      if($stmt) { 
       $_SESSION['main_notice'] = "Successfully Updated!"; 
          header('Location: profile.php'); 
           exit; 

      }else{ 
        $_SESSION['main_notice'] = "Some error, try again"; 
        header('Location: '.$_SERVER['PHP_SELF']); 
       } 

    $stmt->close(); 

} // 我PHP代碼}

//mysqli_close($con); 
      ?> 

      <?php 
       //include header layout 
       require_once('include/header.php'); 
       ?> 

      <!--------------------------- Redirect based on user type -----------------------> 
       <?php 
        if($_SESSION['user_type'] == 'admin' || $_SESSION['user_type'] == 'leader'){ 

         // include admin header layout 
         require_once('include/admin-header.php'); 

         }elseif($_SESSION['user_type'] == 'member'){ 

         // include member header layout 
         include_once('include/member-header.php'); 

         }else{  

         session_destroy(); 
         header('Location: index.php'); 
         } 
      ?> 
      <!-- check if userId is found, if not throw error ----> 
       <?php 

    $stmt = $con->prepare("SELECT firstname, lastname, skills, user_name, avatar, profession, email, dob, gender, country, phone, bio, address, created_at FROM user WHERE id = ?"); 
    $stmt->bind_param('s', $userId); 
    $stmt->execute(); 
    $stmt->store_result(); 
    if($stmt->num_rows == 0) { 
     echo 'No Data Found for this user'; 
    }else { 
     $stmt->bind_result($firstname, $lastname, $skills, $user_name, $avatar, $profession, $email, $dob, $gender, $country, $phone, $bio, $address, $created_at); 
     $stmt->fetch(); 

     $stmt->close(); 

    } 
       ?> 

這是我的HTML代碼。

      <form name="update" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" id="UploadForm"> 

        <table> 
         <label for="">Avatar</label> 
         <input name="ImageFile" type="file" id="uploadFile"/> 
    <!--      <div> 
          <div class="shortpreview"> 
           <label for="">Previous Avatar </label> 
           <br> 
           <img src="userfiles/avatars/<?php //echo $avatar;?>" width='150' height='150' > 
          </div> 
         </div> --> 
         <div class="col-md-6"> 
          <div class="shortpreview" id="uploadImagePreview"> 
           <label for="">Current Uploaded Avatar </label> 
           <br> 
           <div id="imagePreview"></div> 
          </div> 
         </div> 
        </table> 


           <table> 
           <tr> 
           <td></td> 
           <td></td> 
           <td>Update</td> 
           </tr> 
           <tr> 
           <td><label for = "">First Name</label></td> 
           <td><input type="text" id="firstname" name="firstname" value="<?php echo $firstname; ?>"></td> 
           </tr> 

           <tr> 
           <td><label for = "">Last Name</label></td> 
           <td><input type="text" id="lastname" name="lastname" value ="<?php echo $lastname; ?>"></td> 
           </tr> 

           <tr> 
           <td><label for = "">Postcode</label></td> 
           <td><input type="postcode" id="postcode" name="postcode" value="<?php echo $postcode; ?>"></td> 
           </tr> 

           <tr> 
           <td><label for = "">User Nmae</label></td> 
           <td><input type="user_name" id="user_name" name="user_name" value="<?php echo $user_name; ?>"></td> 
           </tr> 

           <tr> 
           <td><label for = "">Profession Name</label></td> 
           <td><input type="text" id="profession" name="profession" value="<?php echo $profession; ?>"></td> 
           </tr>        

           <tr> 
           <td><label for = "">Phone</label></td> 
           <td><input type="text" id="phone" name="phone" value="<?php echo $phone; ?>"></td> 
           </tr>       

           <tr> 
           <td><label for = "">Email</label></td> 
           <td><input type="text" id="email" name="email" value="<?php echo $email; ?>"></td> 
           </tr> 

           <tr> 
           <td><label for = "">Gender</label></td> 
           <td><input type="text" id="gender" name="gender" value="<?php echo $gender; ?>"></td> 
           </tr> 

           <tr> 
           <td><label for = "">Date Of Birth</label></td> 
           <td><input type="text" id="dob" name="dob" value="<?php echo $dob; ?>"></td> 
           </tr> 


           <tr> 
           <td><label for = "">Addres</label></td> 
           <td><input type="text" id="address" name="address" value="<?php echo $address; ?>"></td> 

           </tr> 


           <tr> 
           <td><label for = "">Country</label></td> 
           <td><input type="text" id="country" name="country" value="<?php echo $country; ?>"></td> 
           </tr> 


           <tr> 
           <td><label for = "">Bio</label></td> 
           <td><input type="text" id="bio" name="bio" value="<?php echo $bio; ?>"></td> 
           </tr> 

           <tr> 
           <td></td>    
           <td><input type="submit" id="update" name="update" value="Update"></td> 
           </tr> 
           </table> 
          </form>  
         </div> 

當我拿出$postcode場我只是增加了它工作得很好,這讓我百思不得其解的問題是什麼什麼通知。正如已經提到的那樣,通過前面的問題,回答者沒有運氣。

+0

自上次工作以來,代碼中發生了哪些變化?這就是你需要找出並回復你上次使用的內容,並使用該文件的副本來添加/使用你現在想要做的事情。你添加了哪些代碼,哪些行是錯誤? –

+0

請確保您重新載入所有內容並清除了緩存,並選擇了正確的表格和數據庫。檢查你的連接,並在每個標題後添加'exit;'。 –

+0

@ Fred-ii-你在40分鐘前的建議是非常真實的......我會在船上看到結果是什麼。 – olaskee

回答

-1

你的問題是在這裏:

if(!($stmt = $con->prepare("UPDATE user SET firstname = ?, lastname = ?, profession = ?, user_name = ?, phone = ?, address = ?, email = ?, bio = ?, 
     gender = ?, postcode = ?, dob = ?, country = ? WHERE id = ?"))) { 
      echo "Prepare failed: (" . $con->errno . ")" . $con->error; 
     } 
     if(!$stmt->bind_param('ssssissssssi', $firstname, $lastname, $profession, $user_name, $phone, $postcode, $address, $email, $bio, $gender, $dob, $country, $userId)){ 
     echo "Binding paramaters failed:(" . $stmt->errno . ")" . $stmt->error; 
       } 

你置於困境PARAM以$郵政編碼,但你沒地方郵政編碼=,在$ CON組>準備()

與此代替它呢? :

if(!($stmt = $con->prepare("UPDATE user SET firstname = ?, lastname = ?, profession = ?, user_name = ?, phone = ?, postcode = ?, address = ?, email = ?, bio = ?, 
     gender = ?, postcode = ?, dob = ?, country = ? WHERE id = ?"))) { 
      echo "Prepare failed: (" . $con->errno . ")" . $con->error; 
     } 
     if(!$stmt->bind_param('ssssissssssi', $firstname, $lastname, $profession, $user_name, $phone, $postcode, $address, $email, $bio, $gender, $dob, $country, $userId)){ 
     echo "Binding paramaters failed:(" . $stmt->errno . ")" . $stmt->error; 
       } 
+0

咦?它在那裏。我看不出這裏的區別。我沒有把握什麼? –

+0

不,不要看看我複製的第一位代碼中的綁定參數和準備語句。在bind_param中有$ postcode,但在$ con> prepare中沒有postcode =? – kerv

+0

'gender =?,postcode =?,'那麼這是什麼? –

相關問題