2013-06-27 163 views
0

我正在開發使用PHP和MySQL的系統,我想從PHP數據插入到我的數據庫..MySQL的INSERT語句語法錯誤

我已經能夠讓MySQL插入我的兩個表,但最後一個是真正的痛苦。這是我的錯誤,我recieving:

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: 


     }}}}?> 
+0

反引用表名 –

+1

這是因爲列名中有一個連字符。使用'' http://stackoverflow.com/questions/885497/hyphens-in-column-names-in-mysql-db – DaveHogan

+0

也關閉[Register Globals](http://php.net/manual/) en/security.globals.php)並使用[mysql_real_escape_string()](http://www.php.net/manual/en/function.mysql-real-escape-string.php) –

回答

0

我一個列有名稱中的連字符,所以我把連字符,並把下劃線代替它。現在一切正常。

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