|
Posted by Ryan on 12/31/06 05:35
Hello. So I'm new to PHP and going through the book PHP and MySQL Web
Development. It's not the greatest book as it fails to continue with
it's example of a simple purchasing script, especially in important
areas such as arrays. I originally had my index.html file consist of
just that, all html. After going through arrays, I decided I could make
it a php script and have an associative array for the products and
prices. However, now I'm not quite sure how to get the quantity for each
product. I was able to replace a ton of html with a simple foreach loop
to go through
the array and create the table. The table includes an input function to
allow the user to input the amount of comics he or she wants. In html
this was easy and in the process.php script, I could call each quantity
variable what it was in the html input tag. I'm not sure how to go about
letting the user input the quantity and getting this information into
the second script that deals with doing all the totaling of the purchase
and writing that information to a file. I'm not even sure if I can do it
the way I want, but I'm not into anything fancy, such as functions or
I'm not exactly sure on sending variables from one script to the next as
what I have now is through html. The code is posted below, although it's
not entirely finished as I wasn't sure if I should make another
variable/array for the quantity or what to use for the "name" of the
input tag. Thanks.
-Ryan
<?php
$products = array('Spiderman'=>4.99, 'Uncanny X-Men'=>2.99,
'Fables'=>11.99);
$qty =
?>
<html>
<head>
<title>Casey's Comics</title>
</head>
<body>
<h1>Casey's Comics</h1>
<pre>Thanks for visiting the newest and greatest website for all your
comic book needs. We have the widest
selection of comic books and graphic novels. All items listed on this
page are current issues. You can, however,
find the most amazing archive collection by following the link at the
side of the page to "Archives". Enjoy...</pre>
<form action="process.php" method=post>
<table border=0>
<tr bgcolor="pink">
<td width=150><font color="blue" style="bold">Comics/Novels</font></td>
<td><font color="blue" style="bold">Prices</font></td>
<td width=15><font color="blue" style="bold">Quantity</font></td>
</tr>
<?php
foreach($products as $name => $price)
echo '<tr><td>'.$name.'</td>'.'<td>'.$price.'</td>'."<td
align='center'><input type='text' name='' size='3'
maxlength='3'></td></tr>";
?>
<tr>
<td>Shipping Address</td>
<td align="center" colspan="2"><input type="text" name="address"
size="20" maxlength="30"></td>
</tr>
<tr>
<td>What new comic are you <br /> excited for the most?</td>
<td colspan="2"><select name="want">
<option value="a">Spiderman Reign
<option value="b">Batman: Dark Night
<option value="c">Origins
<option value="d">Richie Rich
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit
Order"></td>
</tr>
</table>
</form>
</body>
</html>
[Back to original message]
|