繁体   English   中英

MySQL插入语句语法错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM