0

I am developing a system using PHP and MySQL, and I am trying to insert the data from PHP into my database..

I have been able to get MySQL to insert into two of my tables, but this last one is being a real pain. Here is my error I am 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

Here is my code:

     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:


        }}}}?>
3

2 Answers 2

3

It's because the column name has a hyphen in it. Wrap the column names in ` 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
Sign up to request clarification or add additional context in comments.

Comments

0

My one column had a hyphen within the name, so I took the hyphen out and put an underscore in its place. Now everything works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.