English 中文(简体)
passing form variables into a url with php
原标题:

I have the following form which allows a user to select dates/rooms for a hotel reservation.

<form action="booking-form.php" method="post">
  <fieldset>
    <div class="select-date">
      <label>Arrival Date</label>
      <select name="arrd" class="day">
        <option value="1" >1</option>
        ... snip ...
        <option value="24" selected="selected">24</option>
      </select>

      <select name="arrm" class="month">
        <option value="01" >January</option>
        ... snip ...
        <option value="11" selected="selected">November</option>
      </select>
      <select name="arry" class="year">
        <option value="2009" selected="selected">2009</option>
        ... snip ...
      </select>
    </div>
    <div class="more">
    <div class="info">
      <label>Days</label>
      <select name="days">
        <option value="1">01</option>
        ... snip ...
        <option value="7" selected="selected">07</option>
      </select>
    </div>
    <div class="info">
      <label>Rooms</label>
      <select name="rooms">
        <option value="1">01</option>
        ... snip ...
      </select>
    </div>
    </div>
    <input type="submit" value="Check availabilty"/>
    <input type="hidden"  name="submitted" value="TRUE"/>
  </fieldset>
</form>

Here is the php which is supposed to process the variables passed from the form and pass them via a url to the booking provider. Nothing happens when the form is submitted just a white screen with no errors.

<?php

 ini_set ( display_errors ,1);  
 error_reporting (E_ALL & ~ E_NOTICE);  

 if (isset($_POST[ submitted ])){

  $errors = array();

  // A bunch of if s for all the fields and the error messages.


  if (empty($_POST[ arrd ])) {
    $errors[] =  Please select a day ;
} else{
    $arrd = ($_POST[ arrd ]);
}

if (empty($_POST[ arrm ])) {
    $errors[] =  Please select a month ;
} else{
    $arrm = ($_POST[ arrm ]);
}

if (empty($_POST[ arry ])) {
    $errors[] =  Please select a year ;
} else{
    $arry = ($_POST[ arry ]);
}

if (empty($_POST[ non ])) {
    $errors[] =  Please choose a number of nights ;
} else{
    $non = ($_POST[ non ]);
}


if (empty($_POST[ norooms ])) {
    $errors[] =  Please choose a number of rooms ;
} else{
    $norooms = ($_POST[ norooms ]);
}


if (empty($errors)){
$arrdate = $arrd . " " . $arrm ."" . $arry; 

$url ="https://portals.uk.rezlynx.net/DHPPORTAL/wfrmpakquery.aspx?SiteID=DHOLDHALL&arrdate=$arrdate&non=$non&norooms=$norooms";
 header( Location: $url );
exit();

 }

 else{
 foreach($errors as $msg){

 echo"-msg<br/>
";
 }

 }

 ?>

Can anyone see what I am missing?

Thanks in advance..

Dan

最佳回答

If you run your code through PHP s lint checker (php -l), you ll see you have a syntax error at line 62 (the last line)

You re simply missing the curly brace that needs to close the initial "if" statement.

问题回答

The line

header( Location: $url );

should be

header("Location: $url");

Variables aren t evaluated within single-quotes.

The issue could be

header( Location: $url );
exit();

Either try

header( Location:  .$url);
exit();

or

header("Location: $url");
exit();
# using the double quotes will parse the $url variable

Can t you just use that URL in your form s action attribute and set the method to GET?

<form action="https://portals.uk.rezlynx.net/DHPPORTAL/wfrmpakquery.aspx?SiteID=DHOLDHALL" method="get">
    [...]
</form>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签