[英]MySQL insert statement syntax error
我正在使用PHP和MySQL開發系統,並且試圖將PHP中的數據插入數據庫中。
我已經能夠使MySQL插入到我的兩個表中,但是最后一個確實是一個痛苦。 這是我收到的錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-roadway_areas, parking_noMeters, noMeter_days, parking_withMeters, withMeters_d' at line 1
這是我的代碼:
mysql_select_db($database_row_application, $dbc);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!$problem) { // If they magicaly got the forum correct
// Make the insert query
if (empty($errors)) { // Then insert the information to the database
$ai = mysql_query ("INSERT INTO applicant_information (firstname, lastname, address, phone, email, date)
VALUES ('$afn', '$aln', '$aa', '$ap', '$ae', '$d')") or die(mysql_error()); //Run the query
}
if (empty($errors)) { // Then insert the information to the database
$ci = mysql_query ("INSERT INTO closing_information (business_name, address, closure_start_date, closure_end_date, closure_start_time, closure_end_time, rain_date_start, rain_date_end, signs_requested, emergency_vehicle, meter_serial, closing_reason)
VALUES ('$bn', '$ca', '$cbd', '$cbt', '$ced', '$cet', '$rds', '$rde', '$sr', '$ev', '$ms', '$cr')") or die(mysql_error()); //Run the query
}
if (empty($errors)) { // Then insert the information to the database
$fee = mysql_query ("INSERT INTO fees (non-roadway_areas, parking_noMeters, noMeter_days, parking_withMeters, withMeters_days, lane_closures, alley_closure, total_fee) VALUES ('$SDC','$PNMS', '$PNMS', '$PMS', '$PMD', '$VLC', '$AC')") or die(mysql_error()); //Run the query
}
if ($ai) { // If it ran
if ($ci) {
if ($fee) {
mysql_close($dbc); // Close the database connection
// Redirect User
header("Location: payment.php");
$_POST = array();
}
// Clear the posted values, or else they'll float in the void f orever:
}}}}?>
這是因為列名中帶有連字符。 將列名稱包裹在`中,如下所示:
$fee = mysql_query ("INSERT INTO fees (`non-roadway_areas`, parking_noMeters, noMeter_days, parking_withMeters, withMeters_days, lane_closures, alley_closure, total_fee) VALUES ('$SDC','$PNMS', '$PNMS', '$PMS', '$PMD', '$VLC', '$AC')") or die(mysql_error()); //Run the query
我的一欄名稱中有一個連字符,所以我取出了連字符並在其下划線了。 現在一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.