坚持更新玛丽亚数据库中的数据



我想使用此代码更新数据库

$personnel_sql = "UPDATE user_detail SET qualification='$qualification', community='$community', pwd='$pwd', gender='$gender', nationality='$nation', religion='$relegion', ex_serviceman='$ex_service', date_joining='$doj', date_of_retirement='$dor', service_field='$serving_area', j&k_factor='$jkfactor', body_mark='$mark_body', aadhar_no='$aadhar_no' WHERE username='$user'";
//  echo $personnel_sql;
  if ($conn->query($personnel_sql) === TRUE) {
    // echo "Record updated successfully";
    $message = 'Your basic data is successfully updated.';
 echo $message;
    // echo "<SCRIPT type='text/javascript'>
      //   alert('$message');
        // window.location.replace("index.php?get=update/&&username=$user");
    // </SCRIPT>";
 } else {
     echo "Error updating record: " . $conn->error;
 }

我再次收到此错误,为什么

Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '&k_factor='No', body_mark='dharmendra', aadhar_no='2147483647' WHERE username='D' at line 1

此错误的原因是什么

这样做之后

echo $personnel_sql;

它给了我这些数据

UPDATE user_detail SET qualification='10', community='OBC', pwd='Speak Problem, Both ear hearing problem, Left ear hearing problem , right ear hearing problem, There is no hands, Paralised both hands, Only Left hand, Paralised lrft hand, Less finger in left hand, Only Right Hand, Less finger in right hand, No legs, ', gender='MALE', nationality='INDIA', religion='HINDU', ex_serviceman='', date_joining='Apr 16, 2019', date_of_retirement='Apr 23, 2019', service_field='Army', j&k_factor='No', body_mark='dharmendra', aadhar_no='2147483647' WHERE username='Dharmendra_Soni_1554114509'

您的列j&k_factor使用特殊字符,即&(&号((有关更多信息,请参阅 MySQL 文档和此答案(。您需要使用反引号`引用此类标识符。它看起来像`j&kfactor`='$jkfactor'.您甚至可以在查询中引用所有标识符。

我还强烈建议您实现某种形式的预准备语句。请参阅评论 @arkascha 为什么要使用它。

最新更新