yobo Posted January 20, 2010 Share Posted January 20, 2010 Hello all, I have an HTML form were the user can select a product number once they have done that the calling script will output the part number that they selected and show all the details that releate to that part number in a table all the details are stored in a multidimensional array, I know I am ment to use the $_POST function but i have no idea were to put it within my code? Would someone Kindly show me please? My code is shown below Joe My html form <?php /** * @author ohyeah * @copyright 2010 */ ?> <form action="output.php" method="post"> Select a Part number <input type="radio" name="id" value="AC1009"/> AC1009 <input type="radio" name="id" value="AC1010"/> AC1010 <input type="radio" name="id" value="AC1011"/> AC1011 <input type="radio" name="id" value="AC1012"/> AC1012 <input name="inventory" type="submit" value="submit"/> <input type="reset" value="Cancel"/> </form> My porcess script <html><head><title>Inventory Information</title> </head><body></body> <?php /** * @author ohyeah * @copyright 2010 */ $inventory = array ( 'AC1009'=>array('Part'=>'Hammer','Count'=>122,'Price'=>12.50 ), 'AC1010'=>array('Part'=>'Wrench','Count'=>125,'Price'=>25.30 ), 'AC1011'=>array('Part'=>'Drill','Count'=>12,'Price'=>90.50 ), 'AC1012'=>array('Part'=>'Saw','Count'=>10,'Price'=>30.50 ) ); if (isset($inventory[$id])){ echo '<font size="4" color="blue"> '; echo "Inventory Information for Part $id </font>"; echo '<table border=1> <th> ID <th> Part <th> Count <th> Price '; echo "<tr> <td> $id </td>"; echo "<td> {$inventory[$id]['Part']} </td>"; echo "<td> {$inventory[$id]['Count']} </td>"; echo "<td> {$inventory[$id]['Price']} </td></tr>"; } else { echo "Illegal part ID = $id "; } ?> </body></html> Quote Link to comment Share on other sites More sharing options...
schilly Posted January 20, 2010 Share Posted January 20, 2010 Put this above your if statement $id = $_POST['id']; That will get the ID posted from the form and should echo out the part info. Quote Link to comment Share on other sites More sharing options...
yobo Posted January 20, 2010 Author Share Posted January 20, 2010 Thanks schilly Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted January 20, 2010 Share Posted January 20, 2010 <?php if(isset($_POST['submit']) && isset($_POST['id'])): $id = $_POST['id']; $sql = "SELECT * FROM `table_name` WHERE id = '$id' LIMIT 1"; $result = mysql_query($sql) or trigger_error('Failed!', mysql_error()); while($details = mysql_fetch_assoc($result)): echo $details['WHAT YOU WANT TO PRINT']; endwhile; endif; /** * @author ohyeah * @copyright 2010 */ ?> <form action="output.php" method="post"> Select a Part number <input type="radio" name="id" value="AC1009"/> AC1009 <input type="radio" name="id" value="AC1010"/> AC1010 <input type="radio" name="id" value="AC1011"/> AC1011 <input type="radio" name="id" value="AC1012"/> AC1012 <input name="inventory" type="submit" value="submit"/> <input type="reset" value="Cancel"/> </form> James. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.