将数组与预先准备好的语句php、mysql一起使用,跳过空字符串

将数组与预先准备好的语句php、mysql一起使用,跳过空字符串,php,mysql,sql,Php,Mysql,Sql,在学习mysql的预置语句时遇到一些问题 我发现一切正常,然后我遇到了一个新问题,最初的问题是我想跳过mysql更新表单ie:user profile中的空字符串 我试着用php编程,但我不太理解预先准备好的语句,所以我一直在阅读,但没有成功。你能帮我按计划完成这项工作吗?基本上,我试图在预先准备好的状态中使用数组 if (empty($email) && empty($fullname) && empty($address) && empty(

在学习mysql的预置语句时遇到一些问题

我发现一切正常,然后我遇到了一个新问题,最初的问题是我想跳过mysql更新表单ie:user profile中的空字符串

我试着用php编程,但我不太理解预先准备好的语句,所以我一直在阅读,但没有成功。你能帮我按计划完成这项工作吗?基本上,我试图在预先准备好的状态中使用数组

if (empty($email) && empty($fullname)  && empty($address) && empty($country) && empty($state) && empty($city) && empty($postcode) && empty($phone) && empty($password) && empty($random_salt)) {
  echo "Nothing to do....";
  return;
}
else { 
    $state = $_POST['state'];
    $city = $_POST['city'];
    $postcode = $_POST['postcode'];
    $email = $_POST['email'];
    $fullname = $_POST['fullname'];
    $address = $_POST['address'];
    $country = $_POST['country'];
    $phone = $_POST['phone'];
    $merchantID = $_POST['merchantId'];

        // The hashed password from the form
    $password = $_POST['p']; 
    $pass2 = $password;
    $pass = $_POST['password'];

    $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));

    $password = hash('sha512', $password.$random_salt);

    $updates = array();
    if (!empty($email))
      $updates[] = 'email="'.$email.'"';
    if (!empty($address))
      $updates[] = 'address="'.$address.'"';
    if (!empty($country))
      $updates[] = 'country="'.$country.'"';
    if (!empty($state))
      $updates[] = 'state="'.$state.'"';
    if (!empty($city))
      $updates[] = 'city="'.$city.'"';
    if (!empty($postcode))
      $updates[] = 'postcode="'.$postcode.'"';
    if (!empty($phone))
      $updates[] = 'phone="'.$phone.'"';
    if (!empty($password))
      $updates[] = 'password="'.$password.'"';
    if (!empty($random_salt))
      $updates[] = 'salt="'.$random_salt.'"';

    $updates = implode(', ', $updates);

  if ($update_stmt = $mysqli->prepare("UPDATE table SET ? WHERE id = ".$merchantID)) {
    $update_stmt->execute($updates);
    $update_stmt->close();
    //    
    echo '<br><p>';
    echo '<a href="homepage.com"> Account infomation update was a success...</a>';
  }
  else {
    echo "oppps, update didnt work, please report this to admin";
  }

} 

现在我想我已经迷路了,无论我为什么尝试,我似乎都不知道该怎么做,尽管我不完全理解我正在尝试的预先准备好的陈述。

预先准备好的陈述意味着你的陈述看起来像SET phone=?、salt=?,等等。你的陈述看起来一点也不像。谢谢cale,所以唯一的方法就是制作10个左右不同的盲参数来匹配不同的prepair状态?看到我想要完成的了吗?当然有更简单的方法?现在我的电视机看起来像是set phone=$phone,salt=$salt,等等,当然。如果你愿意的话,PDO会让事情变得更简单。否则,这篇文章涵盖了你想要的东西:好吧,我认为PDO是我要走的路,我必须读更多,看起来更简单…不幸的是,没有答案,我们将不胜感激