2013-10-21 25 views
0

我有一个表单来创建请求。通过点击“创建请求”按钮,所有的信息都被添加到“Requests_Table”中。这是完美的。每个请求都有多个项目(至少一个)...并且每个项目都包含自己的特征(这就是为什么我要将此信息存储在单独的表'SerialNumber_Table'上的原因。插入序列号信息(类型,型号,序列号)到“SerialNumber_Table”。我相信我还需要使用mysql_insert_id();每个序列号以正确的REQUEST_ID关联。MySql/PHP - 如何在同一时间将数据插入到两个不同的表中(使用数组)

` //变量序列号

$machineType = mysql_prep($_POST['machineType']); 
    $machineModel = mysql_prep($_POST['machineModel']); 
    $serialNumber = mysql_prep($_POST['serialNumber']); 

  <fieldset class="row2"> 
      <h1><?php echo $LANG['hardware_details']; ?></h1> 
      <p style="margin: 10px 0 10px 0; "> 
       <p style="margin: 10px 0 10px 0; font-size:12px; padding: 0;"><?php echo $LANG['delete_machines']; ?></p> 
       <input type="button" value="<?php echo $LANG['add_machines']; ?>" onClick="addRow('dataTable')" style="width: 100px; padding: 2px 5px 2px 5px; background: #e1e1e1; color: #000; font-weight: bold; font-size: 12px; cursor: pointer;" /> 
       <input type="button" value="<?php echo $LANG['remove_machines']; ?>" onClick="deleteRow('dataTable')" style="width: 130px; margin-left: 10px; padding: 2px 5px 2px 5px; background: #e1e1e1; color: #000; font-weight: bold; font-size: 12px; cursor: pointer;" /> 
      </p> 
      <table id="dataTable" class="form" border="1"> 
       <tbody> 
       <tr> 
        <td><input type="checkbox" style=" width: 30px; "/></td> 
        <td> 
         <label style="margin-left: 10px;"><?php echo $LANG['machineType']; ?></label> 
         <input type="text" value="" id="machineType" name="machineType[]" style="width: 70px; margin: 5px 10px 10px 10px; "> 
        </td> 
        <td> 
         <label for="" style="margin-left: 10px;"><?php echo $LANG['machineModel']; ?></label> 
         <input type="text" value="" id="machineModel" name="machineModel[]" style="width: 70px; margin: 5px 10px 10px 10px;"> 
        </td> 
        <td> 
         <label for="" style="margin-left: 10px;"><?php echo $LANG['serialNumbers']; ?></label> 
         <input type="text" value="" id="serialNumber" name="serialNumber[]" style="width: 120px; margin: 5px 10px 10px 10px;"> 
        </td> 
       </tr> 
       </tbody> 
      </table> 
      <div class="clear"></div> 
     </fieldset> 

      <!-- End Dynamic Forms for Serial Numbers --> 

` 我如何能实现这样的任务呢? 如果有任何帮助,我已将此页的完整代码发布在http://aerco.com.br/stackoverflow/source.txt

任何人都可以在这里指出我正确的方向吗? 在此先感谢您的任何想法

回答

0

将用户提供的串行抑或是预定义的人吗?这应该是您需要插入的代码

$query = "INSERT INTO serialnumber_table(Type,Model,Serial number,request_id) VALUES ($machineType, $machineModel,$serial_number,request_id) 

request_id应该从请求表中获取。

如果我的理解是正确的,插入此代码后

$query = "INSERT INTO requests(
        request_date, requester_name, requester_email, client_name, client_country, opportunity_number, machine_quantity, severity, specialist, created_by, sales_connect 
       ) VALUES (
        '{$request_date}', '{$requester_name}', '{$requester_email}', '{$client_name}', '{$client_country}', '{$opportunity_number}', '{$machine_quantity}', '{$severity}', '{$specialist}', '{$created_by}', '{$sales_connect}' 
       )"; 
相关问题