Page 1 of 1

Mutiple selection problem

Posted: Tue Jun 19, 2007 10:28 am
by ghadacr
I have a script that outputs multiple results from a database with each record outputted with check boxes beside each record(Thats fine)..

When i select multiple records from the results which is passed on to the next page only one of the records is passed. The information being passed to the next script is the record id..

here is the script..(Any help will be appreciated) Cheers....

Code: Select all

<?PHP include 'header.php'; ?>
<?PHP include 'opendb.php'; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/calender.css" rel="stylesheet" type="text/css">
</head>

<body>
<?PHP 
$HotelRoomID = $_GET['HotelRoomID'];
$datefrom = $_GET['datefrom'];
$dateto = $_GET['dateto'];

$sql="SELECT * FROM HotelRooms WHERE HotelRoomID='$HotelRoomID'"; 
$ques="SELECT dbo.Hotels.HotelName FROM Hotels INNER JOIN HotelRooms ON dbo.Hotels.HotelID = dbo.HotelRooms.HotelID WHERE HotelRoomID='$HotelRoomID'";
$query="SELECT dbo.RoomAssociations.RoomAssociation FROM RoomAssociations INNER JOIN HotelRooms ON dbo.RoomAssociations.RoomAssociationID = dbo.HotelRooms.RoomAssociationID WHERE HotelRoomID='$HotelRoomID'"; 
$result=mssql_query($sql);
$res=mssql_query($ques);
$reso=mssql_query($query);

$count=mssql_num_rows($result);


?>


<form method=get name=f1 action='confirmmholdroom.php'>
     <?php
$i=0;
while ($i < $count) {

$rows=mssql_fetch_array($result);
$row=mssql_fetch_array($res);		
$rowe=mssql_fetch_array($reso);
	

?> 
  <table width="85%" border="0">
    <tr> 
      <td width="23%"><strong>Requested from:</strong></td>
      <td width="16%"><strong>Requested to:</strong></td>
      <td width="16%"><strong>Hotel</strong></td>
      <td width="14%"><strong>Room:</strong></td>
      <td width="31%"><strong>Notes</strong></td>
    </tr>
    <tr> 
      <td><?php echo $datefrom; ?> <input type="hidden" name="$datefrom" value="<?PHP echo $datefrom; ?>"> 
        <input type="hidden" name="HotelRoomID" value="<?PHP echo $HotelRoomID; ?>"></td>
      <td><?php echo $dateto; ?> <input type="hidden" name="$dateto" value="<?PHP echo $dateto; ?>"></td>
      <td><?php echo $row['HotelName']; ?> <input type="hidden" name="HotelName" value="<?PHP echo $rows['HotelName']; ?>"></td>
      <td><?php echo $rows['RoomType']; ?> <input type="hidden" name="RoomType" value="<?PHP echo $rows['RoomType']; ?>"></td>
      <td><?php echo $rows['Notes']; ?> <input type="hidden" name="Notes" value="<?PHP echo $rows['Notes']; ?>"></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Sales consultant</td>
      <td><input readonly type="text" name="UserName" value="<?php $nw = new COM("WScript.Network"); echo $nw->username;  ?>"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Surname</td>
      <td><input type="text" name="surname"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp; </td>
    </tr>
    <tr> 
      <td>Forename</td>
      <td><input type="text" name="forename"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Option held:</td>
      <td><input readonly type="text" name="DateHeld" value="<?PHP echo date("d/m/Y"); ?>"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td><input type="submit" name="Submit" value="Hold room">
        <input name="button" type="button" onClick="location.href='http://pb-sql/wintersearch.php'" value="Cancel"></td>
      <td>&nbsp; </td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp; </td>
      <td>&nbsp;</td>
      <td>&nbsp; </td>
      <td>&nbsp;</td>
      <td>&nbsp; </td>
    </tr>
  </table>
</form>

<?PHP 
 ++$i;

}  ?>         <?php 
mssql_close();
?>
</body>
</html>

<P>
<?PHP include 'footer.php'; ?>

Posted: Tue Jun 19, 2007 10:47 am
by volka
Please try this test script

Code: Select all

<html>
	<head><title>...</title></head>
	<body>
		<pre>_POST: <?php print_r($_POST); ?></pre>
		<form method="post" action="?">
			<div>
				<input type="hidden" name="hotel[0][name]" value="hotelA" />
				<input type="hidden" name="hotel[0][from]" value="2007-07-19" />
				<input type="hidden" name="hotel[0][til]" value="2007-07-26" />
				<input type="checkbox" name="hotel[0][book]" /> Hotel A
				<br />
				<input type="hidden" name="hotel[1][name]" value="hotelB" />
				<input type="hidden" name="hotel[1][from]" value="2007-07-18" />
				<input type="hidden" name="hotel[1][til]" value="2007-07-25" />
				<input type="checkbox" name="hotel[1][book]" /> Hotel B
				<br />
				<input type="hidden" name="hotel[2][name]" value="hotelC" />
				<input type="hidden" name="hotel[2][from]" value="2007-07-17" />
				<input type="hidden" name="hotel[2][til]" value="2007-07-24" />
				<input type="checkbox" name="hotel[2][book]" /> Hotel C
				<br />
				<input type="submit" />
			</div>
		</form>
	</body>
</html>
and take a good look at the output.

Posted: Tue Jun 19, 2007 10:58 am
by ghadacr
I'm getting errors, no output at all, hmm although changed the variables it is saying parse error, unexpected and

Notice: Undefined index: HotelRoomID in on line 15

Notice: Undefined index: datefrom in on line 16

Notice: Undefined index: dateto in on line 17

Also on your script you gave me i'm getting
_POST: Array
(
)

Code: Select all

<html>
        <head><title>...</title></head>
        <body>
                 <pre>_POST: <?php print_r($_GET); ?></pre>
                <form method="get" action="roomhold.php">
                        <div>
                                <input type="hidden" name="hotel[0][datefrom]" value="25/06/2007" />
                                <input type="hidden" name="hotel[0][dateto]" value="23/07/2006" />
                                <input type="checkbox" name="hotel[0][HotelRoomID]" /> Hotel A
                                <br />
                                
                                <input type="hidden" name="hotel[1][datefrom]" value="21/07/2006" />
                                <input type="hidden" name="hotel[1][dateto]" value="27/07/2005" />
                                <input type="checkbox" name="hotel[1][HotelRoomID]" /> Hotel B
                                <br />
                               
                                <input type="hidden" name="hotel[2][datefrom]" value="17/07/2007" />
                                <input type="hidden" name="hotel[2][dateto]" value="27/07/2004" />
                                <input type="checkbox" name="hotel[2][HotelRoomID" /> Hotel C
                                <br />
                                <input type="submit" />
                        </div>
                </form>
        </body>
</html>

Posted: Tue Jun 19, 2007 11:25 am
by volka
Please try the my script as-is and play a little with it, i.e. check a checkbox or two and then submit the form and take a look at the output.
Then try again with another combination of checked and unchecked checkboxes and compare the output. Be a little creative.

Posted: Tue Jun 19, 2007 11:34 am
by ghadacr
Reverted back to your code, and all i 'm getting is this error:
Notice: Undefined variable: HotelRoomID in on line 20

Notice: Undefined variable: HotelRoomID in on line 21

Notice: Undefined variable: HotelRoomID in on line 2
2

Posted: Tue Jun 19, 2007 12:23 pm
by volka
Then you didn't test my script as-is, i.e. without any changes or additions or whatever.
Could it be possible that there is something else in the file other than the code I've posted here? Something that contains php code on line 2, 20 and 21? (my script has only one line of php code thus it can only produce a php warning on one line of code)

Posted: Tue Jun 19, 2007 4:14 pm
by feyd
Maybe a caching problem?

Posted: Tue Jun 19, 2007 4:22 pm
by ghadacr
Well i'm feeding it in the same page as above, so there is other PHP Code....but i dont think that code will affect the outcome of the results....

Posted: Tue Jun 19, 2007 4:40 pm
by volka
Obviously it does. :roll:

The example is meant as a standalone script, a file of its own, nothing else.

Posted: Tue Jun 19, 2007 5:02 pm
by superdezign
Volka's telling you to just take the code he had as a new page and try it. Play around with it and learn it. Nowhere in his script is there a variabled named $HotelRoomID on line 2, 20, or 21.

Posted: Wed Jun 20, 2007 4:53 am
by ghadacr
Ok misunderstanding...checking know

Posted: Wed Jun 20, 2007 5:28 am
by ghadacr
Ok Volks script work's but how would you translate that, so it can work for my script....because i want the user to be able to select mutiple entrys, then output the reults on the other page:

Here is the script

User selection script:

Code: Select all

<?PHP
extract($_GET);
$daterep = str_replace("/","-",$datefrom);
$datereps = str_replace("/","-",$dateto);


$newdate = date ("d M Y", strtotime ($daterep)); 
$newdates = date ("d M Y", strtotime ($datereps)); 

setcookie("from", $newdate, time(  )+600);
setcookie("to", $newdates, time(  )+600);
setcookie("hotel", $subcat, time(  )+600);


?>
<?PHP include 'opendb.php'; ?>

<?PHP include 'header.php'; ?>

<?php 


if(isset($_GET))
{

extract($_GET);

$subcat = $_GET['subcat'];
$optionsheld = $_GET['optionsheld'];
$confirmedroom = $_GET['confirmedroom'];
$cat = $_GET['cat'];
$Season = $_GET['Season'];


$query = mssql_init ("sp_SearchRooms"); 

mssql_bind($query, "@DateTo", $newdate, SQLVARCHAR);

mssql_bind($query, "@Season", $Season, SQLVARCHAR);

mssql_bind($query, "@resortID", $cat, SQLINT2);

mssql_bind($query, "@DateFrom", $newdates, SQLVARCHAR);

mssql_bind($query, "@HotelID", $subcat, SQLVARCHAR);

mssql_bind($query, "@SearchConfirmed", $groupname, SQLVARCHAR);

mssql_bind($query, "@SearchOptions", $optionsheld, SQLVARCHAR);
if (($result = mssql_execute($query)) === false) 
{ 
    die('Could not execute the query ' . $sql ); 
} 



?> 
<?PHP

$count=mssql_num_rows($result);	

 if ($count == 0)
  {
echo "<p>Sorry, your search returned no results</p><br><input type='button' value='Retry' onClick='history.go(-1)'>";

} else {

?>
<form action="roomhold.php" method="get"> 
  <table width="108%" border="0">
    <tr> 
     <td width="19%"></td>
	  <td width="8%"><strong>Room Type:</strong></td>
      <td width="8%"><strong>Available From:</strong></td>
      <td width="8%"><strong>Available To:</strong></td>
	  <td width="9%"><strong>Requested from</strong></td>
	  <td width="9%"><strong>Requested To:</strong></td>
      <td width="5%"><strong>Notes</strong></td>
      <td width="44%">&nbsp;</td>
    </tr>
    <?php 

	
while ($row = mssql_fetch_array($result)) 
{ 
    echo '<tr>';
	echo '<td><a href="roomdetails.php?HotelRoomID=' . $row['HotelRoomID'] . '">More information on hotel room</a></td>'; 
    echo '<td>' . $row['RoomType' ] . '</td>'; 
	echo '<td>' . $row['AvailableFrom' ] . '</td>';
	echo '<td>' . $row['AvailableTo' ] . '</td>';
	echo '<td><input type="hidden" name="datefrom" value="' . $datefrom . '" />' . $datefrom .'</td>';
	echo '<td><input type="hidden" name="dateto" value="' . $dateto . '" />' . $dateto .'</td>';
	echo '<td>' . $row['Notes' ] . '</td>';
    echo '<td><input type="checkbox" name="HotelRoomID" value="' . $row['HotelRoomID'] . '" />Select  ' . $row['RoomType'] .' to update</td>'; 
    echo '</tr>'; 

}





?>
    <tr> 
      <td colspan="6"><input type="Submit" value="Hold Room"> <INPUT name="button" type="button" onClick="location.href='http://pb-sql/admin.php'" value="Cancel"> 
      </td>
    </tr>
  </table> 
</form> 

<?PHP include 'footer.php'; ?>
<?PHP }} 
?>
Vaildation script

Code: Select all

<?PHP include 'header.php'; ?>
<?PHP include 'opendb.php'; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/calender.css" rel="stylesheet" type="text/css">
</head>

<body>
<?PHP 

$HotelRoomID = $_GET['HotelRoomID'];
$datefrom = $_GET['datefrom'];
$dateto = $_GET['dateto'];

$sql="SELECT * FROM HotelRooms WHERE HotelRoomID='$HotelRoomID'"; 
$ques="SELECT dbo.Hotels.HotelName FROM Hotels INNER JOIN HotelRooms ON dbo.Hotels.HotelID = dbo.HotelRooms.HotelID WHERE HotelRoomID='$HotelRoomID'";
$query="SELECT dbo.RoomAssociations.RoomAssociation FROM RoomAssociations INNER JOIN HotelRooms ON dbo.RoomAssociations.RoomAssociationID = dbo.HotelRooms.RoomAssociationID WHERE HotelRoomID='$HotelRoomID'"; 
$result=mssql_query($sql);
$res=mssql_query($ques);
$reso=mssql_query($query);

$count=mssql_num_rows($result);


?>


<form method=get name=f1 action='confirmmholdroom.php'>
     <?php
$i=0;
while ($i < $count) {

$rows=mssql_fetch_array($result);
$row=mssql_fetch_array($res);		
$rowe=mssql_fetch_array($reso);
	

?> 
  <table width="85%" border="0">
    <tr> 
      <td width="23%"><strong>Requested from:</strong></td>
      <td width="16%"><strong>Requested to:</strong></td>
      <td width="16%"><strong>Hotel</strong></td>
      <td width="14%"><strong>Room:</strong></td>
      <td width="31%"><strong>Notes</strong></td>
    </tr>
    <tr> 
      <td><?php echo $datefrom; ?> <input type="hidden" name="$datefrom" value="<?PHP echo $datefrom; ?>"> 
        <input type="hidden" name="HotelRoomID" value="<?PHP echo $HotelRoomID; ?>"></td>
      <td><?php echo $dateto; ?> <input type="hidden" name="$dateto" value="<?PHP echo $dateto; ?>"></td>
      <td><?php echo $row['HotelName']; ?> <input type="hidden" name="HotelName" value="<?PHP echo $rows['HotelName']; ?>"></td>
      <td><?php echo $rows['RoomType']; ?> <input type="hidden" name="RoomType" value="<?PHP echo $rows['RoomType']; ?>"></td>
      <td><?php echo $rows['Notes']; ?> <input type="hidden" name="Notes" value="<?PHP echo $rows['Notes']; ?>"></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Sales consultant</td>
      <td><input readonly type="text" name="UserName" value="<?php $nw = new COM("WScript.Network"); echo $nw->username;  ?>"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Surname</td>
      <td><input type="text" name="surname"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp; </td>
    </tr>
    <tr> 
      <td>Forename</td>
      <td><input type="text" name="forename"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Option held:</td>
      <td><input readonly type="text" name="DateHeld" value="<?PHP echo date("d/m/Y"); ?>"></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td><input type="submit" name="Submit" value="Hold room">
        <input name="button" type="button" onClick="location.href='http://pb-sql/wintersearch.php'" value="Cancel"></td>
      <td>&nbsp; </td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp; </td>
      <td>&nbsp;</td>
      <td>&nbsp; </td>
      <td>&nbsp;</td>
      <td> </td>
    </tr>
  </table>
</form>

<?PHP 
 ++$i;

}  ?>         <?php 
mssql_close();
?>
</body>
</html>

<P>
<?PHP include 'footer.php'; ?>

Posted: Wed Jun 20, 2007 5:42 am
by volka
ghadacr wrote:Ok Volks script work's but how would you translate that, so it can work for my script....because i want the user to be able to select mutiple entrys, then output the reults on the other page:
What did you learn from the example?
What is $_POST['hotel]?
Are there changes in the output when a checkbox was checked?
What does that tell you about changes in $_POST['hotel']?
Does it work with more than one checkbox?
How can you tell e.g. the checkbox was set for Hotal A and Hotel C but not Hotel B?
How can you detected such changes in an php array?

Posted: Wed Jun 20, 2007 6:10 am
by ghadacr
Volka i apperciate the advise, i'm sorry if i'm getting on your nerves, it seems that you got alot of experience, but this script has driven me CRAZY( :twisted: )...

The script does really what i want it to do, if HOTEL A is selected then the script will return
on
and ect etc.....allowing for mutiple selection...

But i'm not sure how to proceed with it in my script... Sorry....