I got a form which has two buttons, lets say if confirmed is pressed then it gets redirected to page 1, if release gets pressed it gets redirected to page 2.... The problem i'm having is that it does not redirect to the appropiate page: Here is the code: <?PHP $Confirm = $_GET['Confirm']; //$Release = $_GET['Release']; if (!isset($_GET['Confirm'])) { header('Location: http://www.some.com/conaddops.php'); } ?> PHP: Thanks in advance...
if (!isset($_GET['Confirm']) && !$_GET['Confirm']) { PHP: isset() only checks if the variable exists, even if it is empty. e.g. script.php?confirm= $_GET['confirm'] is set and is equal to a 0 length string
<?php if (!empty($_GET['confirm'])) header("Location: location:http://www.other.com/"); ?> ... PHP: Place the php code before any HTML tags
<form action=http://www.someone/check.php method="get"> <table width="76%" border="0" bgcolor="#FFFF99"> <tr> <td width="13%"><strong>Hotel name:</strong></td> <td width="9%"><strong>Date held:</strong></td> <td width="12%"><strong>Room type:</strong></td> <td width="27%"><strong>Requested by sales consultant</strong>:</td> <td width="39%"> </td> </tr> <?php while ($rowe = mssql_fetch_array($res)) { echo '<tr>'; echo '<td>' . $rowe['HotelName' ] . '</td>'; echo '<td>' . $rowe['DateOptionHeld' ] . '</td>'; echo '<td>' . $rowe['RoomType' ] . '</td>'; echo '<td>' . $rowe['UserName' ] . '</td>'; echo '<td><input type="hidden" name="AvailableFrom" value="' . $rowe['AvailableFrom'] . '"><input type="radio" name="HotelRoomID" value="' . $rowe['HotelRoomID'] . '" />Select ' . $rowe['HotelName'] .' to release/confirm</td>'; echo '</tr>'; } ?> <tr> <td height="27" colspan="7"><strong> <input type="submit" name="Confirm" value="Confirm"> <input type="submit" name="Release" value="Release"> </strong> </td> </tr> </table> </form> <?PHP } echo "<p>"; ?> PHP:
I got it partly working, If i press the release button it works, but i press the confirm button i get the following error: <?PHP $HotelRoomID = $_GET['HotelRoomID']; $AvailableFrom = $_GET['AvailableFrom']; $Confirm = $_GET['Confirm']; $Release = $_GET['Release']; if (!isset($_POST['Confirm']) && !empty($_POST['Confirm'])) { header('Location: http://pb-sql/conaddops.php? HotelRoomID='.$HotelRoomID.'&AvailableFrom='.$AvailableFrom.''); } elseif ((!isset($_POST['Release']) && !empty($_POST['Release']))) { header('Location: http://pb-sql/releaseaddops.php? HotelRoomID='.$HotelRoomID.'&AvailableFrom='.$AvailableFrom.''); } ?> PHP:
It isn't an error, it is a notice and for this case, just ignore it Or use this to hide notices: <?php error_reporting(E_ALL ^ E_NOTICE); $HotelRoomID = $_GET['HotelRoomID']; $AvailableFrom = $_GET['AvailableFrom']; $Confirm = $_GET['Confirm']; $Release = $_GET['Release']; ... PHP:
(!isset($_POST['Confirm']) && !empty($_POST['Confirm']))'Confirm']) && !empty($_POST['Confirm'])) PHP: won't work as you're using GET on your form. Your logic is also back to front - referring to your original message, you're saying you want to redirect if $_GET['Confirm'] IS set, but your code checks if it's NOT set (the ! before isset()) Edit: what you actually need, as far as I understand. <?php $HotelRoomID = $_GET['HotelRoomID']; $AvailableFrom = $_GET['AvailableFrom']; if (isset($_GET['Confirm'])) { header('Location: http://pb-sql/conaddops.php?HotelRoomID='.$HotelRoomID.'&AvailableFrom='.$AvailableFrom.''); } elseif (isset($_GET['Release'])) { header('Location: http://pb-sql/releaseaddops.php?HotelRoomID='.$HotelRoomID.'&AvailableFrom='.$AvailableFrom.''); } ?> PHP: