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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.