943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 18
  • PHP RSS
Sep 2nd, 2010
0

sending variables from a form with an array

Expand Post »
hey i desperately need to know the answer for a project if anyone can help...

i and retrievin info from a DB and desplayin it in a dynamic table. then if the <select value='1'> in the form i need to send a variable accross to another page.

the code is like this:

$href = "HowManyPeople.php?daysOfMonth=".$dayArrive."&monthOfYear=".$month."&year=".$year."&nights=".$nights;

require("dbCon.php");

if($con)
{
mysql_select_db($database);
$res = mysql_query("select * from roomfed where RoomName not in (select RoomName from bookingfed)");

echo "<form id='form1' name='form1' method='post' action='".$href."'>";

while($row = mysql_fetch_assoc($res))
{
echo "<div id='RoomBorder'>";
echo "<table width='100%'><tr><th colspan='2'>". $row["RoomName"] ."</th></tr>";
echo "<tr><td colspan='2' align='left'>".$row["Description"]."</td></tr>";
echo "<tr><td><b>Max Guests ".$row["RoomCapacity"]."</b></td><td><b>Rates</b></td></tr>";
echo "<tr><td></td><td>".$row["RoomInSeasonPrice"]."</td></tr>";
echo "<tr><td>How many units do you require: <select name='HowManyUnits' id='HowManyUnits'>
<option selected='selected' value='0'>Units</option>
<option value='1'>1</option>

</select></td><td align='Left'><input type='submit' name='Next' id='Next' value='Next'/></td></tr>";
echo "</table><br><br>";
echo "</div><br>";
}

//<!--End of div RoomBorder-->
echo "</form>";

so there will be multiple tables with info about each room in each. then if the value from the <options> tag is == 1 i need to send across the 'RoomName'. then i can reconnect to the DB and retrieve all info for that room.

please if anyone can help it is urgent.

many thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010
Sep 2nd, 2010
1
Re: sending variables from a form with an array
I'm not sure that I totally understand your question based on your explanation but let me take a stab at it. If I understood it incorrectly, then you'll need to clarify:

If you need to send the RoomName from module to module2 that is just a (straightforward) use of a form variable. Your option (0 or 1) will be sent to module2 and so will the room name. You can do this as a free form entry of a text field (not the best solution) or provide them with a drop-down list that you load with all of the possible room names or have a checkbox or radio button beside each room that you are displaying in the first module. Whichever way you do it, module2 will know which room name to use when it reads the database.
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Sep 2nd, 2010
0
Re: sending variables from a form with an array
require("dbConnect.php");

if($con)
{
mysql_select_db($database);
$res = mysql_query("select * from roomfed where RoomName not in (select RoomName from bookingfed)");

echo "<form id='form1' name='form1' method='post' action='third.php'>";

$i = 1;

while($row = mysql_fetch_assoc($res))
{
echo "<div id='RoomBorder'>";
echo "<table width='100%'><tr><th colspan='2'>". $row["RoomName"] ."</th></tr>";
echo "<tr><td colspan='2' align='left'>".$row["Description"]."</td></tr>";
echo "<tr><td><b>Max Guests ".$row["RoomCapacity"]."</b></td><td><b>Rates</b></td></tr>";
echo "<tr><td></td><td>".$row["RoomInSeasonPrice"]."</td></tr>";
echo "<tr><td>Select desired room:<input type='checkbox' name='SelectRoom[]' value='".$i."'/></td><td align='Left'><input type='submit' name='Next' id='Next' value='Next' /></td></tr>";
echo "</table><br><br>";
echo "</div><br>";

$i++;
}

//<!--End of div RoomBorder-->
echo "</form>";
}

-----------------------
third.php
---------

if(isset($_POST['SelectRoom[]']))
{
for($j = 0; $j<='SelectRoom[]'; $j++)
{
echo "SelectRoom[".$j."]";
}
}

does this look sort of right...?????????

so basically i need to get the checked check boxes and display the Room name for each.

can you give me any advice??
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Syntax Question
Next Thread in PHP Forum Timeline: Validation of data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC