MySQL插入语句语法错误

时间:2013-06-27 14:56:52

标签: php mysql

我正在使用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:


        }}}}?>

2 个答案:

答案 0 :(得分:3)

这是因为列名称中包含连字符。将列名包装在`like below:

 $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

答案 1 :(得分:0)

我的一列在名称中有一个连字符,所以我取出连字符并在其位置加上下划线。现在一切正常。

相关问题