Jump to content


Photo

newbie needs help with passing varibles between a form and a summary page


  • Please log in to reply
4 replies to this topic

#1 ebailey

ebailey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 August 2006 - 03:22 PM

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 returned
if (mysql_num_rows($results) > 0) {
    // yes
    // print them one after another
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_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 memory
mysql_free_result($results);

// close connection
mysql_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

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 05:06 PM

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)
RTFM is an almost extinct art form, it should be subsidized.

#3 ebailey

ebailey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 August 2006 - 06:32 PM

as requested - thanks!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.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 database
mysql_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.id
FROM
  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 returned
if (mysql_num_rows($results) > 0) {
    // yes
    // print them one after another
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='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 memory
mysql_free_result($results);

// close connection
mysql_close($connection);

echo "<table width='80%' border='0' align='center'>";
echo "<tr>";
echo "<td width='23%'>&nbsp;</td>";
echo "<td width='19%'>&nbsp;</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>&nbsp;</p>";
echo "<p align='center'>";
echo "<label>";
echo "<input name='Submit' type='submit'/>";
echo "</label>";
echo "</p>";

echo "</form>";

?>
</body>
</html>

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 07:24 PM

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):
// see if any rows were returned
if (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>";
}

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#5 ebailey

ebailey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 August 2006 - 08:24 PM

thanks so much - your code works great.

Ed




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users