View Single Post
  #1 (permalink)  
Old 10-04-2008, 01:48
KarlG KarlG is offline
Junior Member
 
Join Date: Dec 2005
Location: UK
Posts: 19
Unhappy Referencing $_POST data against MySQL

Firstly, apologies for being rubbish. I'm not particularly fluent with PHP, i've just been working with tutorials and manuals etc from the web. Bare with me while I wobble out an explanation attempt....

Basically I have a form (www.karlgunton.com/fluid) which has the contents auto generated from a MySQL database. On submitting the form, I just want it to go to a "total" page which will then just get emailed (not looking forward to figuring that out).

So i've got the form to submit an ID for the item in the database, and a price choice number (the amount to multiply the price in the database by) which i then just want to reference against the MySQL Server database, so then i can output all the details again neatly & nicely, then hopefully add a bit of maths to give a total.

How on earth do i get the array from the $_POST turned into auto generated lines of MySQL Server output?

ie. array output:
ID - amount
2 - 1
4 - 2

mysql equivalent:
name & price on row of id
Budwieser 10.99
Carlsberg 21.98

It might make more sense if you view the url and click submit.

The initial page with the drinks:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mysql table test</title>
</head>
<body>
<br><br>


<?php

$link = mysql_connect( "localhost", "", "" );
if ( ! $link ) {
  die( "Couldn't connect to MySQL" );
};
$database = "karlg_fluid";
mysql_select_db( $database ) or die (  "Couldn't open database: ".mysql_error() );

 $beer = "SELECT * FROM drinks where producttype='beer'";
 $beerboxes = mysql_query($beer) or die(mysql_error());  

?>
<center>

<form action="total.php" method="post" name="form2" id="form2" >


<table height="249" cellspacing="0" cellpadding="0" width="802" border="0" id="table3">
<tbody>
<tr><td width="736" height="65"><img class="" height="65" alt="" width="802" border="0" src="images/Fluid-DrinkCategoryBox_TOP-Beers.gif" /></td></tr>
<tr>
<td width="802" background="images/Fluid-DrinkCategoryBox_MIDDLE.gif" height="172" align="center">
<table id="table4" height="197" cellspacing="0" cellpadding="0" width="802" border="0">
<tbody>
<tr>                    
<?php                   
// START AUTO GENERATION OF TABLES FOR CATEGORY
while ($a_row=mysql_fetch_array($beerboxes)) 
{
print '
<td>
<p align="center"><img border="0" src="images/'.stripslashes($a_row['imageurl']).'">
<br>
<font size="3"><font face="Arial">'.stripslashes($a_row['productname']).'</font>
<br>
<font size="1"><font face="Arial">'.stripslashes($a_row['productinfo']).'</font>
<br>
<select size="1" name="'.stripslashes($a_row['id']).'">
<option>Choose</option>
<option value="1">One - £'.stripslashes($a_row['productprice']).'</option>
<option value="2">Two - £'.stripslashes(format_number($a_row['productprice'] *2)).'</option>
<option value="3">Three - £'.stripslashes(format_number($a_row['productprice'] *3)).'</option>
<option value="4">Four - £'.stripslashes(format_number($a_row['productprice'] *4)).'</option>
<option value="5">Five - £'.stripslashes(format_number($a_row['productprice'] *5)).'</option>
</select>

</td>
';				
}
?>	
</tr>
</tbody>
</table>
</td>
</tr>
<tr><td width="736" height="12" align="center"><img class="" height="12" alt="" width="802" border="0" src="images/Fluid-DrinkCategoryBox_BOTTOM.gif" /></td></tr>
</tbody>
</table>
<br><br>


[rest of the boxes not added yet]



<input type="submit" name="Submit" value="not setup yet">

</p>
</form>
</center>
</tr>
</table>
</body>
</html>
the current nothingness of total page
Code:
<table cellspacing="0" cellpadding="2">
<tr> 
 <td><u>Drink</u></td>
 <td><u>Amount</u></td> 
</tr> 
<?php 
while (list ($drinkid, $drinkprice) = each($_POST))
 if($drinkprice != "Choose" AND $drinkid != "Submit") {   // stops from echoing irrelevant fields
 { 
 echo "<tr><td> "; 
 echo $drinkid; 
 echo " (i want to find this id in MySQL Server then output name, desc etc from that)";
 echo "</td><td>";
 echo $drinkprice; 
 echo " (amount to multiply price found in the MySQL Server table)";
 echo "</td></tr>"; 
 } 
echo "<br />";
} 

?>
</table>
Apologies if it seems like i'm trying to get someone to 'write me a script', but i just cant find anything on the web for this kind of thing.

Most scripts assume i have two constant results in the array like 'NAME - Bob' (for example) which i know would just be a sort of find $_POST[name] in database type of thing, but i dont have a 'name' field

...or something.

My head hurts.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by flesso; 10-04-2008 at 11:26.
Reply With Quote