Jump to content

Change Uri


Leftfield

Recommended Posts

Hi all

 

I'm new to PHP so i might ask easy stuff

 

Here is my Scenario

 

I click a button .. this work fine

 

But in the  php code that runs after the button is clicked i need to change the Website uri (link)

 

to something like this after button postback

 

index?name=value

 

How am i gonna do this . I tried header function but it did not work well

 

 

Any suggestion please

Link to comment
Share on other sites

Ok here is the code

 

it runs on button click

 

What i want to do is chage the uri on button click

 

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">

 

<?php
/* 
* Created on 2011/02/01
* Created by Marinus
*/
   //Step 1  date validation//

   if(isset($_POST['submit'])) {

     $startDate = strtotime($_POST['startdate']);
     $endDate = strtotime($_POST['enddate']);
      if($startDate != false && $endDate != false){
        $startDate = date("Y-m-d",$startDate);
        $endDate = date('Y-m-d',$endDate);
         SetDates($startDate,$endDate);
        }

      else
      {
      echo "Please select both dates!";
      }

   }
function SetDates($start,$end){
    $connection =   mysql_connect('*****', '*****', '******')   ;
    mysql_select_db('OnlineBookings');
    $query  = //Hidin
    $result = mysql_query($query);
    $nonAvailableRooms = "";
      while($row = mysql_fetch_array($result, MYSQL_ASSOC))
      {

        $nonAvailableRooms .="'". $row['Code'] ."',";


        
      }
      if($nonAvailableRooms == "")
      {
          ShowAllRooms();

      }
      else
          {

          Codes($nonAvailableRooms);

          }

    echo mysql_error();
   }


   function Codes($findedCodes){

   $findedCodes =  substr($findedCodes, 0, -1);
    $query  = "SELECT (Code),Description,Notes  FROM Item WHERE code NOT IN ($findedCodes)";
    $result = mysql_query($query);
    $i = 0;
      while($row = mysql_fetch_array($result, MYSQL_ASSOC))
      {
        $i++;

        echo "<div style='border:1px solid black'><a title=\"".$row['Notes']." href=\"rooms/".$row['Code'].".jpg\"><img height=120px width=140px src=\"rooms/".$row['Code'].".jpg\" border=0></a>";
        echo "<br/>Room Code :{$row['Code']} <br> Room Description : {$row['Description']}
       <br/> <input id='chk_$i' type='checkbox' name='option$i' onclick='showValue(this);' value='{$row['Code']}'><br> Book this room.  </div>" ;

      }
      if($i == 0){
          echo "There is no available rooms.";
      }
      else
          {
         
          
          header('index.php?name=Next');
          }

   }
   function ShowAllRooms()
   {
     $query  = "SELECT *  FROM item";
     $result = mysql_query($query);
     $i = 0;
      while($row = mysql_fetch_array($result, MYSQL_ASSOC))
      {
        $i++;
         echo "<div style='border:1px solid black'><a href=\"rooms/".$row['Code'].".jpg\"><img height=120px width=140px src=\"rooms/".$row['Code'].".jpg\" border=0></a>";
        echo "<br/>Room Code :{$row['Code']} <br> Room Description : {$row['Description']}
        <br/><input id='chk_$i' type='checkbox' name='option$i' onclick='showValue(this);' value='{$row['Code']}'>Book this room.<br>  </div>" ;

      }
        
header('index.php?name=Next');

   }

   //Step 2 the code to run after dates is valid


?>

 

 

So when all is validated i want the button to chage uri to

 

header('index.php?name=Next');

 

and then change button value to  Next or $_SELF or some vairable that i can run to change button click procedure

 

todo step 2

<input id="Submit" type="submit" name="submit" value="<?php  ?>"/></div>

 

Hope someone can help me

 

Thanks

Link to comment
Share on other sites

The header function is used to set http headers. You want to set the location header.

 

header('Location: index.php?name=Next');

 

Also, the http states that the location header should be a complete uri, this includes the domain name, not just a relative uri. (Most browsers will handle it either way, but best to be safe than sorry)

 

So, you'll want something like....

 

header('Location: yourdomain.com/index.php?name=Next');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.