0

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


        }}}}?>
4

2 回答 2

3

这是因为列名中有一个连字符。将列名包装在 ` 中,如下所示:

 $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
于 2013-06-27T15:00:14.043 回答
0

我的一列的名称中有一个连字符,所以我去掉了连字符并在其位置放置了一个下划线。现在一切正常。

于 2013-06-27T15:02:56.550 回答