ebailey Posted August 4, 2006 Share Posted August 4, 2006 Hi,I am sure this is easy but I am totally confused and need help.What I am trying to do is to generate a form from a database query and then recieve user import that is then passed to a summary page where the user decides if they want to place the order. I made the form and it is generated from the database with no issues. Here is the code// execute query$results = mysql_query($query) or die ("Error in query: $query. ".mysql_error());// see if any rows were returnedif (mysql_num_rows($results) > 0) { // yes // print them one after anotherwhile($row = mysql_fetch_row($results)) {echo "<table width='80%' border='1' align='center' bgcolor='#FFFFFF'>";echo "<tr>";echo "<td width='23%' colspan='2'></td>";echo "<td width='19%'>$row[6]</td>";echo "<td width='26%'>$row[13]</td>";echo "<td width='32%'><input name='order_amount' type='text' value='0' size='6' maxlength='6'></td>";echo "</tr>";echo "<tr>";echo "<td width='23%'>Product Description</td>";echo "<td colspan='4'>$row[9]</td>";echo "</tr>";} echo "</table>";}else { // no // print status message echo "No rows found!";}// free result set memorymysql_free_result($results);// close connectionmysql_close($connection);The query has two records and the code generates two tables but the text input boxes have the same name so I have no idea how to pass that user input to the summary page since using a POST will only pass info from one box to the summary page. Any idea how to pass the user inpt to the summary page? Is there some way to increment the test box name to make it unque?Thanks!Ed Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 4, 2006 Share Posted August 4, 2006 You are not building a form, but a table. How do you pass that to the summary routine? Please show the complete code of the form.Ronald 8) Quote Link to comment Share on other sites More sharing options...
ebailey Posted August 4, 2006 Author Share Posted August 4, 2006 as requested - thanks!<!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-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?php$qid = intval($_GET['quote_num']);// set database server access variables:// open connection$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");// select databasemysql_select_db($db) or die ("Unable to select database!");// create query$query = "SELECT DISTINCT quotes.name, product_bundles.name, quotes.purchase_order_num, quotes.quote_num, product_bundles.description, quotes.total, products.name, users.first_name, users.last_name, products.description, accounts.name, contacts.first_name, contacts.last_name, products.discount_price, contacts.portal_name, product_bundles.total, product_bundles.idFROM quotes_accounts INNER JOIN quotes ON (quotes_accounts.quote_id = quotes.id) INNER JOIN accounts ON (quotes_accounts.account_id = accounts.id) INNER JOIN quotes_contacts ON (quotes.id = quotes_contacts.quote_id) INNER JOIN contacts ON (quotes_contacts.contact_id = contacts.id) INNER JOIN product_bundle_quote ON (quotes.id = product_bundle_quote.quote_id) INNER JOIN users ON (quotes.created_by = users.id) INNER JOIN product_bundles ON (product_bundle_quote.bundle_id = product_bundles.id) INNER JOIN product_bundle_product ON (product_bundles.id = product_bundle_product.bundle_id) INNER JOIN products ON (product_bundle_product.product_id = products.id)WHERE (contacts.portal_name = 'Jane') AND (`quotes`.`quote_num` = '$qid')";// execute query$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());$rows = mysql_fetch_row($result);echo "<form action='summary.php' method='post'>";echo "<p align='center'><strong>Order form for Quote $rows[3] - $rows[0] </strong></p>";echo "<table width='80%' border='1' align='center' bgcolor='#FFFFFF'>";echo "<tr align='left' valign='middle'>";echo "<td><strong>Customer</strong></td>";echo "<td>$rows[10]</td>";echo "<td><strong>PO Number </strong></td>";echo "<td>";echo "<input name='po_num' type='text' value='000' size='6' maxlength='6' /></td>";echo "</tr>";echo "<tr align='left' valign='middle'>";echo "<td><strong>Customer Contact</strong></td>";echo "<td>$rows[11] $rows[12]</td>";echo "<td><strong>Sales Contact</strong></td>";echo "<td>$rows[7] $rows[8]</td>";echo "</tr>";echo "</table>";echo "<p align='center'><strong>Quoted Items</strong></p>";echo "<table width='80%' border='0' align='center' bgcolor='#FFFFFF'>";echo "<tr>";echo "<td width='23%'><strong>Quanity</strong></td>";echo "<td width='19%'><strong>Product</strong></td>";echo "<td width='26%'><strong>Unit Price</strong></td>";echo "<td width='32%'><strong>Order Items</strong></td>";echo "</tr>";echo "</table>";// execute query$results = mysql_query($query) or die ("Error in query: $query. ".mysql_error());// see if any rows were returnedif (mysql_num_rows($results) > 0) { // yes // print them one after anotherwhile($row = mysql_fetch_row($results)) {echo "<table width='80%' border='1' align='center' bgcolor='#FFFFFF'>";echo "<tr>";echo "<td width='23%' colspan='2'></td>";echo "<td width='19%'>$row[6]</td>";echo "<td width='26%'>$row[13]</td>";echo "<td width='32%'><input name='order1' type='text' value='0' size='6' maxlength='6'></td>";echo "</tr>";echo "<tr>";echo "<td width='23%'>Product Description</td>";echo "<td colspan='4'>$row[9]</td>";echo "</tr>";} echo "</table>";}else { // no // print status message echo "No rows found!";}// free result set memorymysql_free_result($results);// close connectionmysql_close($connection);echo "<table width='80%' border='0' align='center'>";echo "<tr>";echo "<td width='23%'> </td>";echo "<td width='19%'> </td>";echo "<td width='26%' align='center' valign='middle'><strong>Total</strong></td>";echo "<td width='32%'><input name='total' type='text' value='0.00' size='6' maxlength='6'/></td>";echo "</tr>";echo "</table>";echo "<p> </p>";echo "<p align='center'>";echo "<label>";echo "<input name='Submit' type='submit'/>";echo "</label>";echo "</p>";echo "</form>";?></body></html> Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 4, 2006 Share Posted August 4, 2006 You can dynamically change the text field name so you'll get name='order0 and the next generate a name='order1'. In your receiving you must then handel the $_POST['order'0'] and $_POST['order1'] variables. Code as follows for that part (look for the $i variable):[code]// see if any rows were returnedif (mysql_num_rows($results) > 0) { // yes // print them one after another $i=0 while($row = mysql_fetch_row($results)) {echo "<table width='80%' border='1' align='center' bgcolor='#FFFFFF'>";echo "<tr>";echo "<td width='23%' colspan='2'></td>";echo "<td width='19%'>$row[6]</td>";echo "<td width='26%'>$row[13]</td>";echo "<td width='32%'><input name='order".$i++."' type='text' value='0' size='6' maxlength='6'></td>";echo "</tr>";echo "<tr>";echo "<td width='23%'>Product Description</td>";echo "<td colspan='4'>$row[9]</td>";echo "</tr>";}[/code]Ronald 8) Quote Link to comment Share on other sites More sharing options...
ebailey Posted August 4, 2006 Author Share Posted August 4, 2006 thanks so much - your code works great.Ed 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.