PHP表单不保存到表

I have a page called service.php that uses a modal window to open a form. The action on the form was service.php.

<div class="modal hide fade" id="myServiceModal" tabindex="-1" role="dialog" aria-labelleby="myModalLabel" aria-hidden="true">
   <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h3 id="myModalLabel">Service Failure Form</h3>
   </div>
   <div class="modal-body">
   <p>
     <form class="well-small" action="service.php" method="POST" id="serviceModalForm" name="serviceModalForm">
        <label>Container Selected</label>
        <input type="text" name="containerNumber" id="containerNumber" />
        <label>Bol Selected</label>
        <input type="text" name="bolNumber" id="bolNumber" />
        <input type="submit" id="modal-form-submit" name="submit" class="btn btn-success btn-small" href="#" value="Save" />

<?php

$bol = $_POST['bolNumber'];                     
$container = $_POST['containerNumber'];

if(isset($_POST['submit'])){
     $sql_query_string = 
           "INSERT INTO import_view_svc_fail (bol, container_num) VALUES 
                                             ('$bol', '$container');";
 if(mysql_query($sql_query_string)){
    echo ("<script language='javascript'>
            window.alert('Added New Service Failure')
            </script>");
}
?>
      </form>

This form worked, and it saved to the appropriate table.

Here is my problem: I had to move that form to another page, called dispatch.php. All I did was copy the code, and put it on dispatch.php.

I changed the action of the form to dispatch.php, and that's where I think the problem starts. When I change the action back to service.php, it works for whatever reason.

When I remove the form completely from service.php, the form on dispatch.php no longer works.

I've tried everything to make this work. I removed all of the code from service.php. I even removed the whole file from the folder.

Any insight would be helpful.

You tell the script what to do but you don't tell it to do it.

In order to excecute a your SLQ-query you have to use mysql_query($sql_query_string);

You will also want to connect to your database. Take a look at http://php.net/manual/de/function.mysql-connect.php for more information.

so.. you change the action in service.php:

<form class="well-small" action="dispatch.php" method="POST" id="serviceModalForm" name="serviceModalForm">

Move to dispatch.php

<?php

if(isset($_POST['submit'])) 
{
     $bol = (isset($_POST['bolNumber'])) ? $_POST['bolNumber'] : ''; 

     $container = (isset($_POST['containerNumber'])) ? $_POST['containerNumber'] : '';         

     if (!empty($bol) && !empty($container))
     {
         $sql_query_string = 
               "INSERT INTO import_view_svc_fail (bol, container_num) VALUES 
                                                ('$bol', '$container');";
         // run the query here

         print "<br/><br/>".$sql_query_string."<br/><br/>";
     }
     else { print "<br/><br/>empty values;<br/>"; } 
}
else { print "<br/><br/>\$_POST info not received;<br/>"; }  

?>

prints (after submit):

INSERT INTO import_view_svc_fail (bol, container_num) VALUES ('input one value', 'input two value');

you probably should check and make sure you got all your post values inside the if(isset($_POST['submit'])) statement, too. or re-work the logic as a whole... it depends if you want to allow blank values, too.

Also, read up on sql injection and why you should learn to use mysqli_ or pdo.