0
如何在php中设置多个来自多个select查询的变量值。 这里是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
我通过邮寄方式收到来自我的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>
  
<p><label>User Name:</label> <input id="usrname" name="usrname"type="text" autocomplete="off"></p>
  
<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>
  
<p><label>Size:</label> <input id="usize" name="usize" type="text" autocomplete="off"></p>
  
<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>
请请停止使用mysql_query,mysql_result类似古代,不赞成和不稳定的方法。 – edigu
你的第一个(虚拟)代码中没有提到'usrname'。请发布您的真实代码。 –
@foozy对不起,我在这是新的,首先我试图创建过程,但我无法在PHP中调用,所以我不得不通过旧的方法.. plz帮助我,如果你知道新的方法来设置多个变量 – Nfunchar