3

我有一个名为 service.php 的页面,它使用模式窗口打开表单。表单上的操作是 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>

此表单有效,并保存到相应的表中。

这是我的问题:我不得不将该表单移动到另一个页面,称为 dispatch.php。我所做的只是复制代码,并将其放在 dispatch.php 上。

我将表单的操作更改为 dispatch.php,这就是我认为问题开始的地方。当我将操作更改回 service.php 时,无论出于何种原因,它都会起作用。

当我从 service.php 中完全删除表单时,dispatch.php 上的表单不再起作用。

我已经尝试了一切来完成这项工作。我从 service.php 中删除了所有代码。我什至从文件夹中删除了整个文件。

任何见解都会有所帮助。

4

2 回答 2

0

你告诉脚本要做什么,但你不告诉它去做。

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.

于 2013-11-04T17:30:59.970 回答
0

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.

于 2013-11-04T17:33:19.933 回答