簡體   English   中英

PHP准備好的語句未執行

[英]PHP prepared statement not executing

我只是重寫了一些PHP代碼以使其更安全,但出現了問題。 我的代碼假設將用戶個人資料圖片保存在uploads文件夾中,然后將其保存到數據庫中,然后顯示給他們。 但這沒有發生。 唯一發生的事情是圖片被保存在uploads文件夾中,僅此而已。 我沒有任何錯誤。 有人可以幫我修復我的代碼嗎?

更新!

我只是試過這段代碼:

$username = isset($_SESSION['username']) ? $_SESSION['username'] : "";
$userPic = isset($_SESSION['userPic']) ? $_SESSION['userPic'] : "";
var_dump($userPic);


$info = date('Y-m-d_H-i-s');

if(!empty($username))
{
    if (isset($_FILES['fileToUpload'])) {

      $errors= array();
      $file_name = $_FILES['fileToUpload']['name'];
      $file_size = $_FILES['fileToUpload']['size'];
      $width = 1500;
      $height = 1500;
      $file_tmp = $_FILES['fileToUpload']['tmp_name'];
      $file_type = $_FILES['fileToUpload']['type'];
      $tmp = explode('.',$_FILES['fileToUpload']['name']);
      $file_ext=strtolower (end ($tmp));

      $extensions= array("jpeg","jpg","png");

      if(in_array($file_ext,$extensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }

       if ($file_size > 8097152) {
        $errors[] = 'File size must be 2 MB';
    }

      if ($width > 1500 || $height > 1500) {
            echo"File is to large";
      }

      if(empty($errors)==true)
      {
         move_uploaded_file($file_tmp,"uploads/".date('Y-m-d_H-i-s').$file_name);

      $stmt = $conn->prepare("UPDATE users SET userPic=?, date_time=? WHERE username"); 

      $stmt->bind_param('ss', $userPic, $date_time);

      /* execute prepared statement */
       $stmt->execute();

     printf("%d Row inserted.\n", $conn->affected_rows);

     /* close statement and connection */

      }else{
         print_r($errors);
         echo"Couldn't upload picture";
      }

}}
else
{
    echo "Invalid Username";
}

這就是我-1 Row inserted.

嘗試這個

$stmt = $conn->prepare("UPDATE users SET userPic=?, date_time=? ");


$stmt->bind_param('ss', $userPic, $date_time);

$userPic = 'pic url';
$date_time = 'date';


/* execute prepared statement */
$stmt->execute();

printf("%d Row inserted.\n", $stmt->affected_rows);

/* close statement and connection */
$stmt->close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM