0

我如何在 php.ini 中从多个选择查询中设置多个变量值。这是php代码(trans.php)

<?php
include('config.inc');
$pname       = $_POST['pname'];
$usrname     = $_POST['usrname'];
$iname       = $_POST['iname'];
$udec        = $_POST['udec'];  
$usize       = $_POST['usize'];
$qty         = $_POST['qty'];   
$lname       = $_POST['lname']; 

$p_id = mysql_result(mysql_query("SELECT `id` FROM `project_master` WHERE ( `Project_Code` = '" . $_POST['pname']  . "') "),0);
$user_id = mysql_result(mysql_query("SELECT `u_id` FROM `user` WHERE ( `user_name` = '" . $_POST['usrname']. "') "),0);
$i_id = mysql_result(mysql_query("SELECT `id` FROM `item_master` WHERE ( `item_name`    = '" . $_POST['iname']  . "') "),0);
$unit_id = mysql_result(mysql_query("SELECT `id` FROM `unit_mstr` WHERE( `Unit_Name`    = '" . $_POST['udec']   . "') "),0);
$loc_id = mysql_result(mysql_query("SELECT `id` FROM `location_mstr` WHERE( `l_name`       = '" . $_POST['lname']  . "') "),0);
$sql= " INSERT INTO project_transaction_header(project_id, u_id, item_Id, unit_id,Size, Qty, location_id, Created_On, Created_By, Modified_on, Modified_By) VALUES ('$p_id','$user_id','$i_id',$unit_id','$item_size','$item_qty','$loc_id',now(),'‌​system',now(),'system');";

但我得到了错误

Notice: Undefined index: usrname in C:\xampp\htdocs\alogin\ptrans.php on line 14

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 6 

Notice: Undefined index: iname in ..\..\ptrans.php on line 15

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 7 

Notice: Undefined index: udec in ..\..\ptrans.php on line 16

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 8 

Notice: Undefined index: lname in ..\..\ptrans.php on line 17

我通过 post 方法从我的 html 页面接收 vaules..

这是我的 HTML 代码,我称之为 PHP Transition.html

<HTML>
<head>
</head>
  <body>
   <div id="loginAdmin" class="animate form" >
   <form class="cbp-mc-form" action="ptrans.php" id="trans" method="post" >
   <div class="cbp-mc-column">
   <p><label>Project Name:</label> <input name="pname"id="pname" type="text" autocomplete="off"></p>
   &nbsp&nbsp
   <p><label>User Name:</label> <input id="usrname" name="usrname"type="text" autocomplete="off"></p>
   &nbsp&nbsp
   <p><label>Itme Name:</label> <input id="iname" name="iname" type="text" autocomplete="off"></p>
   </div>
  <div class="cbp-mc-column">                                   
  <p><label>Unit Dec:</label> <input id="udec" name="udec" type="text" autocomplete="off"></p>
  &nbsp&nbsp
  <p><label>Size:</label> <input id="usize" name="usize" type="text" autocomplete="off"></p>
  &nbsp&nbsp
  <p><label>QTY:</label> <input id="qty" name="qty" type="text" autocomplete="off"></p>
    </div>
  <div class="cbp-mc-column">   
    <p><label>Location Name:</label> <input name="lname"  id="lname" type="text" autocomplete="off"></p>
     </div>
     <div style="margin-top: 530px;"class="cbp-mc-submit-wrap"><input class="cbp-mc-submit" type="submit" value="SUBMIT" />
<input class="cbp-mc-submit" type="reset"  name="reset" id="reset"  value="Reset" />
</div>                              
    </form>                      
    </div>
    </body>
    </html> 
4

1 回答 1

0

用户var_dump($_POST);查看变量的实际名称。Usrname 和其他索引根本没有在 post 数组中定义。

在 php 中使用mysqli函数而不是 mysql,因为它们已经被弃用,并且它们不会在未来的 php 版本中使用。

于 2013-08-25T16:19:27.883 回答