Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Multiple forms on one page


[SOLVED] Multiple forms on one page

Reply
  #1 (permalink)  
Old 11-07-08, 08:26 AM
Denethor Denethor is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Question [SOLVED] Multiple forms on one page

As you can see from the linked picture below, everything is pretty much working correctly at the moment - but I have one more problem to overcome before I get to the sending the info to an ordering page part.

http://www.fileden.com/files/2008/2/8/1747909/table.jpg

The problem I'm having now is that each of those tables has a form but when I click the "add to order" (which at the moment simply calculates the price) The price appears in every single black total box regardless of which one you click.

I think this is because the field/radio names are the same for each form element and they need to be unique... and I'm not sure how to remedy this.

My other question is, would there be a way to auto update the forms so that once you have selected your options you don't need to click any buttons to display the correct price before clicking "add to order" which would then send the form to another php page.

Here is my current code:

PHP Code:

<?PHP


// login info

$user_name "root";
$password "";
$database "lemboss";
$server "localhost";

// Connect To Database

$db_handle mysql_connect($server$user_name$password);
$db_found mysql_select_db($database$db_handle);

// connection test script
/*
if ($db_found) {
print "Database Found ";
mysql_close($db_handle);

}
else {
print "Database NOT Found" . $db_handle;
}
print "Connection to the Server opened";
*/

$size $_POST['size'];
$material $_POST['material'];
$quantity $_POST['quantity'];

$total $size $material $quantity;
$price number_format($total2);

$result mysql_query("SELECT * FROM health_and_safety");
$columns 2;
$num_rows mysql_num_rows($result);

//Start Content
echo "<table width=\"710\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

//Table Loop
for($i 0$i $num_rows$i++) {
$row mysql_fetch_array($result);
    
if (
$i $columns ==0) {
echo 
"<tr>";
}
echo 
"<td align=\"center\">";

//Start Order Box

echo "<form method=\"post\" action=\"health.php\" name=\"form" $row['id'] . "\">";
echo 
"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#666666\">";

echo 
"<tr align=\"center\" valign=\"middle\">";
echo 
"<td width=\"10\" height=\"270\" rowspan=\"16\">&nbsp;</td>";
echo 
"<td width=\"150\" height=\"20\" colspan=\"2\"><div align=\"center\" class=\"tablehead\">" $row['id'] . "</div></td>";
echo 
"<td width=\"30\" height=\"270\" rowspan=\"16\">&nbsp;</td>";
echo 
"<td width=\"150\" height=\"20\" colspan=\"3\"><div align=\"center\" class=\"tablehead\">MATERIALS</div></td>";
echo 
"<td width=\"10\" height=\"270\" rowspan=\"16\">&nbsp;</td>";
echo 
"</tr>";
  
echo 
"<tr>";
echo 
"<td width=\"150\" height=\"150\" colspan=\"2\" rowspan=\"10\" align=\"center\"><a href=\"img/signs/" $row['picture'] . ".jpg\" target=\"_blank\"><img src=\"img/signs/thumbs/" $row['picture'] . "_thumb.jpg\" width=\"150\" height=\"150\"></a></td>";
echo 
"<td width=\"130\" height=\"20\" colspan=\"2\" class=\"tabletext\">" $row['material_1'] . "</td>";
echo 
"<td width=\"20\" height=\"20\"><input name=\"material\" type=\"radio\" value=\"" $row['vinyl'] . "\" checked></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"150\" height=\"10\" colspan=\"3\"><img src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td>";
echo 
"</tr>";
  
echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\" colspan=\"2\" class=\"tabletext\">" $row['material_2'] . "</td>";
echo 
"<td width=\"20\" height=\"20\">";
echo 
"<input type=\"radio\" name=\"material\" value=\"" $row['3mm_foam'] . "\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"150\" height=\"10\" colspan=\"3\"><img src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\" colspan=\"2\" class=\"tabletext\">" $row['material_3'] . "</td>";
echo 
"<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"material\" value=\"" $row['5mm_foam'] . "\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"150\" height=\"10\" colspan=\"3\"><img src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\" colspan=\"2\" class=\"tabletext\">" $row['material_4'] . "</td>";
echo 
"<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"material\" value=\"" $row['3mm_alu_panel'] . "\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"150\" height=\"10\" colspan=\"3\"><img src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td>";
echo 
"</tr>";
  
echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\" colspan=\"2\" class=\"tabletext\">" $row['material_5'] . "</td>";
echo 
"<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"material\" value=\"" $row['3mm_solid_alu'] . "\"></td>";
echo 
"</tr>";
  
echo 
"<tr>";
echo 
"<td width=\"150\" height=\"10\" colspan=\"3\"><img src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"150\" height=\"20\" colspan=\"2\"><div align=\"center\" class=\"tablehead\">AVAILABLE SIZES</div></td>";
echo 
"<td width=\"130\" height=\"20\" colspan=\"2\" class=\"tabletext\">" $row['material_6'] . "</td>";
echo 
"<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"material\" value=\"" $row['pvc_banner'] . "\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\"><div align=\"left\" class=\"tabletext\">" $row['size_1_dim'] . "</div></td>";
echo 
"<td width=\"20\" height=\"20\"><input name=\"size\" type=\"radio\" value=\"" $row['size_1'] . "\" checked></td>";
echo 
"<td width=\"75\" height=\"40\" rowspan=\"2\"><div align=\"left\" class=\"tablehead\">QUANTITY</div></td>";
echo 
"<td width=\"75\" height=\"40\" colspan=\"2\" rowspan=\"2\" align=\"center\"><input name=\"quantity\" type=\"text\" id=\"quantity\" value=\"0\" size=\"5\" maxlength=\"10\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\"><div align=\"left\" class=\"tabletext\">" $row['size_2_dim'] . "</div></td>";
echo 
"<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"size\" value=\"" $row['size_2'] . "\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"130\" height=\"20\"><div align=\"left\" class=\"tabletext\">" $row['size_3_dim'] . "</div></td>";
echo 
"<td width=\"20\" height=\"20\"><input type=\"radio\" name=\"size\" value=\"" $row['size_3'] . "\"></td>";
echo 
"<td width=\"75\" height=\"20\" bgcolor=\"#000000\"><div align=\"center\" class=\"tabletext\">&pound;";
echo 
$price;
echo 
"</div></td>";
echo 
"<td width=\"75\" height=\"20\" colspan=\"2\"><input type=\"image\" name=\"submit\" src=\"img/add_button.gif\" width=\"75\" height=\"20\" value=\"send\"></td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"150\" height=\"20\" colspan=\"2\">&nbsp;</td>";
echo 
"<td width=\"150\" height=\"20\" colspan=\"3\">&nbsp;</td>";
echo 
"</tr>";

echo 
"<tr>";
echo 
"<td width=\"10\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"10\" height=\"1\"></td>";
echo 
"<td width=\"130\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"130\" height=\"1\"></td>";
echo 
"<td width=\"20\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"20\" height=\"1\"></td>";
echo 
"<td width=\"30\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"30\" height=\"1\"></td>";
echo 
"<td width=\"75\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"75\" height=\"1\"></td>";
echo 
"<td width=\"55\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"55\" height=\"1\"></td>";
echo 
"<td width=\"20\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"20\" height=\"1\"></td>";
echo 
"<td width=\"10\" height=\"1\" valign=\"top\"><img src=\"transparent.gif\" alt=\"\" width=\"10\" height=\"1\"></td>";
echo 
"</tr>";

echo 
"</table>";
echo 
"</form>";
//End Order Box

if (($i $columns) == (columns 1) || ($i 1) == $num_rows)
{
echo 
"</tr>";
}
}
echo 
"</table>";
?>
Anyone got any idea of the best way to proceed here?

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 11-07-08, 09:01 AM
aburrows182 aburrows182 is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Ashtead, Surrey, UK
Posts: 61
Thanks: 0
Thanked 1 Time in 1 Post
this may be useless, but give the submit buttons each a unique name, then create an array for all the submit names so it can then run the array and recognise the submit button from the form you clicked.
Reply With Quote
  #3 (permalink)  
Old 11-10-08, 04:33 AM
Denethor Denethor is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by aburrows182 View Post
this may be useless, but give the submit buttons each a unique name, then create an array for all the submit names so it can then run the array and recognise the submit button from the form you clicked.
I can give each submit button a unique name easy enough - but I don't know much about arrays, I'm learning about them at the moment.

Not sure exactly what you meant though.

I'm a real newb at all this so forgive me if I act a bit dense
Reply With Quote
  #4 (permalink)  
Old 11-14-08, 06:09 AM
Denethor Denethor is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Actually I have an idea that this is the problem, ignore the rest of my ramblings:

PHP Code:

$size $_POST['size'];

$material $_POST['material'];
$quantity $_POST['quantity'];

$total $size $material $quantity;
$price number_format($total2); 
The variable total is being printed in each form because that is exactly what the script is telling it to do... so.

I'm guessing that each form item needs to have a unique name, but I'm not sure how to make a script to calculate the form values if there's potentially unlimited element names that the values are coming from...

And wouldn't the total variable have to be unique for each form also so that it only prints in the correct place?

The guy above probably already answered this question but I'm too inexperienced/dense to see it

I may have gone about this completely the wrong way... or is my code so far salvageable?

Last edited by Denethor; 11-14-08 at 06:14 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multi window tabbed navigation przemyskibatiar JavaScript 2 05-05-08 11:40 AM
Update multiple fields at once on a page Snowball PHP 3 03-12-08 11:42 AM
View page through page TheCase PHP 10 10-03-07 10:02 AM
Passing a variable to another page tapir PHP 8 02-16-05 05:38 PM
HELP!! Multiple forms on one page??? tcooper PHP 5 07-03-04 08:59 PM


All times are GMT -5. The time now is 08:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.