du21064 2015-10-05 12:30
浏览 45

将变量从表单传递到下一页并放入sql语句php

Here is what I am trying to do. I have a dropdown (and or excel type look) that I need to pull data from the database. When I have an item selected I need to pass the info to the next page via a session. I have the drop down pulling from the database but I need to list Name and address in the dropdown.

If this is not possible I can do a list of items from a search but I will need to make the id a link to pass the id to the next page where I need to build a report.

If you can give me some info on this I would appreciate it.

Here is what I have for code on the dropdown

Code: Select all

<?php   
// declare database connection variables.
$host = "localhost";
$username = "root";
$password = "";
$db_name = "sample";
$tbl_name = "tbl_report";

// connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql = "SELECT id, name, address FROM $tbl_name";
$result = mysql_query($sql) or die(mysql_error());

$dropdown = "<form action='report.php' method='post'>"; 

$dropdown .= "<select name='items' class='select'>";

while ($row = mysql_fetch_assoc($result)) {
$dropdown .= '<option value="' . $row['id'] . '">' . 
$row['name'] . ' - ' . $row['address'] . '</option>';;
}
$dropdown .= "
</select>";
$dropdown .= "<input type='submit' name='submit' value='Submit'>";
$dropdown .= "</form>"; //closing the form tag
echo $dropdown;
?>

What I need to do is pass the ID to the next page and have the $id show up in the code for my next sql statement.

Here is the code that I have for the next page sql statement.

select * from $tbl_name where id = (this is where I get hung up on.)

What I need is a way to pass the $row['id'] to the next page and put that in the sql code and then use the get method to display the info on the form of that page.

Here is the setup of the pages. select-report.php (this is where the drop down is) --> report.php.

Here is the form for report.php where i need to carry over the value of id and do a sql of select * from $tbl_name where id=[$post=items]; Then i need to use the $get to put all the items in the form below:

<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td width="20%">Water Purveyor
<input name="water-purveyor" type="text" id="water-purveyor" size="35" />
</td>
<td colspan="2">Facility Contact
<input type="text" name="facility-contact" id="facility-contact" /></td>
<td colspan="2">Facility Address
<input type="text" name="facility-address" id="facility-address" /></td>
</tr>
<tr>
<td>Manufacturer
<input type="text" name="manufacturer" id="manufacturer" /></td>
<td width="20%">State
<select name="state" id="state">
</select></td>
<td width="20%">Model #
<input name="model-num" type="text" id="model-num" size="10" /></td>
<td width="20%">Serial #
<input name="serial-num" type="text" id="serial-num" size="10" /></td>
<td width="20%">Meter #
<input name="meter-num" type="text" id="meter-num" size="10" /></td>
</tr>
<tr>
<td>Owner
<input type="text" name="owner" id="owner" /></td>
<td>Phone #
<input name="phone-num" type="text" id="phone-num" size="12" /></td>
<td>Caged
<input type="checkbox" name="caged" id="caged" /></td>
<td>Locked
<input type="checkbox" name="locked" id="locked" /></td>
<td>Code key
<input name="code-key" type="text" id="code-key" size="6" /></td>
</tr>
<tr>
<td colspan="2">Owner Address
<input name="owner-address" type="text" id="owner-address" size="50" /></td>
<td>Owner City
<input type="text" name="owner-city" id="owner-city" /></td>
<td>Owner State
<select name="owner-state" id="owner-state">
</select></td>
<td>Owner Zip
<input name="owner-zip" type="text" id="owner-zip" size="10" /></td>
</tr>
<tr>
<td>Contact
<input type="text" name="contact" id="contact" /></td>
<td>Contact Phone
<input name="contact-phone" type="text" id="contact-phone" size="10" /></td>
<td>&nbsp;</td>
<td>Other</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">Facility Name
<input name="facility-name" type="text" id="facility-name" size="40" /></td>
<td colspan="3">Assembly Address
<input name="assembly-address" type="text" id="assembly-address" size="75" /></td>
</tr>
<tr>
<td colspan="5">Onsite Location
<input name="onsite-location" type="text" id="onsite-location" size="75" /></td>
</tr>
<tr>
<td colspan="5">email Address
<input name="email" type="text" id="email" size="125" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>SHUTOFF VALVES</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td>N/A</td>
<td>Good</td>
<td>Poor</td>
<td>Fail</td>
</tr>
</table></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Valve 1</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><input type="checkbox" name="v1-na" id="v1-na" /></td>
<td><input type="checkbox" name="v1-good" id="v1-good" /></td>
<td><input type="checkbox" name="v1-poor" id="v1-poor" /></td>
<td><input type="checkbox" name="v1-fail" id="v1-fail" /></td>
</tr>
</table></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Valve 2</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><input type="checkbox" name="v2-na" id="v2-na" /></td>
<td><input type="checkbox" name="v2-good" id="v2-good" /></td>
<td><input type="checkbox" name="v2-poor" id="v2-poor" /></td>
<td><input type="checkbox" name="v2-fail" id="v2-fail" /></td>
</tr>
</table></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Assembly Replacement?
<input type="checkbox" name="assembly-replacement" id="assembly-replacement" /></td>
<td>if yes Serial #
<input type="text" name="assembly-replacement-serial" id="assembly-replacement-serial" /></td>
<td>New Installation 
<input type="checkbox" name="new-install" id="new-install" /></td>
<td>Permit #
<input type="text" name="permit-num" id="permit-num" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Containment
<input type="checkbox" name="containment" id="containment" /></td>
<td>Isolation
<input type="checkbox" name="isolation" id="isolation" /></td>
<td colspan="2">Assembly Ground Clearance
<input type="text" name="assembly-ground-clearance" id="assembly-ground-clearance" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Domestic
<input type="checkbox" name="domestic" id="domestic" /></td>
<td>Irrigation
<input type="checkbox" name="irrigation" id="irrigation" /></td>
<td>Fire Line
<input type="checkbox" name="fire-line" id="fire-line" /></td>
<td>Alarmed Fire Line
<input type="checkbox" name="alarmed-fire-line" id="alarmed-fire-line" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><strong><em><u>Double Check Balve Assembly Repair</u></em></strong></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Repairs</td>
<td>Check Valve 1</td>
<td>&nbsp;</td>
<td>Check Valve 2</td>
<td>&nbsp;</td>
</tr>
<tr>
<td rowspan="3">&nbsp;</td>
<td>Cleaned 
<input type="checkbox" name="cv1-repair-cleaned" id="cv1-repair-cleaned" /></td>
<td>&nbsp;</td>
<td>Cleaned
<input type="checkbox" name="cv2-repair-cleaned" id="cv2-repair-cleaned" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>Replaced</strong></td>
<td>&nbsp;</td>
<td><strong>Replaced</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Rubber Kit
<input type="checkbox" name="cv1-rubber-kit" id="cv1-rubber-kit" /></td>
<td>&nbsp;</td>
<td>Rubber Kit
<input type="checkbox" name="cv2-rubber-kit" id="cv2-rubber-kit" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Other 
<input type="checkbox" name="cv1-other" id="cv1-other" /></td>
<td>&nbsp;</td>
<td>Other
<input type="checkbox" name="cv2-other" id="cv2-other" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">Comments      
<textarea name="cv1-other-comments" id="cv1-other-comments" cols="45" rows="5"></textarea></td>
<td colspan="2">Comments
<textarea name="cv2-other-comments" id="cv2-other-comments" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">Initial Test By      
<input name="initial-test-by" type="text" id="initial-test-by" size="50" /></td>
<td colspan="2">Certified Tester #
<input type="text" name="certified-tester-num" id="certified-tester-num" /></td>
<td>Test Date/Time
<input type="text" name="test-date-time" id="test-date-time" /></td>
</tr>
<tr>
<td>Pass      
<input type="checkbox" name="initial-test-pas" id="initial-test-pas" /></td>
<td>Fail
<input type="checkbox" name="initial-test-fail" id="initial-test-fail" /></td>
<td colspan="2">Calib Expire Date
<input type="text" name="calib-expire-date" id="calib-expire-date" /></td>
<td>Guage Serial #
<input type="text" name="gague-serial-num" id="gague-serial-num" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">Repair Test By
<input name="repair-test-by" type="text" id="repair-test-by" size="50" /></td>
<td colspan="2">Repair Date/Time
<input type="text" name="repair-date-time" id="repair-date-time" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">Final Test by
<input name="final-test-by" type="text" id="final-test-by" size="50" /></td>
<td colspan="2">Certified Tester #
<input type="text" name="ft-certified-tester-num" id="ft-certified-tester-num" /></td>
<td>Test Date/Time
<input type="text" name="ft-date-time" id="ft-date-time" /></td>
</tr>
<tr>
<td>Pass
<input type="checkbox" name="ft-pass" id="ft-pass" /></td>
<td>Fail
<input type="checkbox" name="ft-fail" id="ft-fail" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="5">Comments
<textarea name="comments" id="comments" cols="80" rows="5"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">Video upload <input type="file" name="uploadvideo"  /></td>
<td colspan="2">Image 1 <input type="file" name="uploadimage"  /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">Image 2 <input type="file" name="uploadimage2"  /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">Image 3 <input type="file" name="uploadimage3"  /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">Image 4 <input type="file" name="uploadimage4"  /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">Image 5 <input type="file" name="uploadimage5"  /></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
  • 写回答

4条回答 默认 最新

  • douxunwei7083 2015-10-05 12:41
    关注

    you can use jquery when to get the selected value like this

    $("#dropdownid").change(function({  var vals = $(this).val(); })
    

    then when you are redirecting to next page then add it as get parameter

    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。