Jump to content

Having problems with accessing arrays from a form


yobo

Recommended Posts

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>

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.