卡在更新玛丽亚数据库中的数据

时间:2019-04-06 10:21:01

标签: php sql

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

$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'

1 个答案:

答案 0 :(得分:3)

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

我也强烈建议您实施某种形式的准备好的语句。请参阅comment by @arkascha,为什么要使用它。