Not redirecting

Discussion in 'PHP' started by ghadacr, Aug 8, 2007.

  1. #1
    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...
     
    ghadacr, Aug 8, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    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
     
    krt, Aug 8, 2007 IP
  3. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the response, i changed the code, but i'm still not getting redirected....:confused:
     
    ghadacr, Aug 8, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Post your HTML form.
     
    nico_swd, Aug 8, 2007 IP
  5. adsblog

    adsblog Active Member

    Messages:
    659
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    70
    #5
    <? if (!(isset($_GET['confirm']))) { header("location:http://www.other.com"); ?>
    PHP:
    test it ! :confused:
     
    adsblog, Aug 8, 2007 IP
  6. euler

    euler Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    if (!empty($_GET['confirm'])) header("Location: location:http://www.other.com/");
    ?>
    ...
    PHP:
    Place the php code before any HTML tags
     
    euler, Aug 8, 2007 IP
  7. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <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%">&nbsp;</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:
     
    ghadacr, Aug 8, 2007 IP
  8. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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:
     
    ghadacr, Aug 8, 2007 IP
  9. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #9
    It isn't an error, it is a notice and for this case, just ignore it :p

    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:
     
    krt, Aug 12, 2007 IP
  10. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #10
    (!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:
     
    void, Aug 12, 2007 IP