简体   繁体   中英

PHP variables passed to new page not showing up

I am looking after a website for someone and I have received all the files from the previous host/webmaster.

The site has an ordering system through paypal but the two variables that are required to be passed from the product page here to the ordering page are not showing up.

The URL of the ordering page appears to have the variables passed correctly as below

http://www.italian-christmas-cookies.com/orderbelow.php?p=55&service=Angel%20Reading

but they are not being shown on the ordering page

The code is shown below.

<b>Personalised
 <?
echo $service;
?></b>
</p>

<p>Price: &pound;<?
echo $p;
?></b>
</p>

So given all that I would expect it to show

Personalised Angel Reading

Price: £55

I'd appreciate any pointers from people with more experience than I have.

Thanks Glenn

UPDATE:

Thanks everyone, all the posts helped and it has given me progress, and a bit of education. I do not know how long ago the original author wrote the code so there might be archaic ways in amongst there.

Carrying on further would similar principles apply for later in the code where the form captures some user input and assigns a variable name such as $dateofbirth below and is used later in an email to the owner? In other words at the moment the date of birth and other fields are not being included in the email

<p>Date of Birth <i>(dd/mm/yyyy)</i><br /><input name="dateofbirth" value="<? echo $dateofbirth;?>" type="text" style="width: 350px;" /></p>


<p><br /><input type="hidden" name="service" value="<?
echo $service;
?>" />

<input type="hidden" name="p" value="<?
echo $p;
?>" />
<input type="submit" value="Order now" /></p>
</form>

The sending email code is here

$emailtext = "From: " . $clientname . "\r\n";
$emailtext .= "Service ordered: " . $service . "\r\n";
$emailtext .= "Price to pay: £" . $p . "\r\n";
$emailtext .= "Date of birth: " . $dateofbirth . "\r\n";
$emailtext .= "Questions:\r\n\r\n" . $questions . "\r\n\r\n";
$emailtext .= "Comments:\r\n\r\n" . $comments . "\r\n\r\n";
$emailtext .= $email;

In summary, is the code above old, archaic, unsupported and in need of modernising to make it work?

Thanks.

To use a GET parameter you must retrieve it from the $_GET array like this:

$_GET['service']

Remember to sanitize $_GET['service'] before displaying to prevent XSS and other possible attacks.

Apparently, the "register globals" feature (http://www.php.net/manual/en/security.globals.php) is turned off in your PHP configuration.

You have two possibilites: Either you turn on "register globals" (which is not longer recommended for good reasons). Or you access the GET parameters in the following way:

<b>Personalised
 <?
echo $_GET["service"];
?></b>
</p>

<p>Price: &pound;<?
echo $_GET['p'];
?></b>
</p>
<p>
    <b>Personalised <?php echo $_GET['service']; ?></b>
</p>

<p>
    <b>Price: &pound;<?php echo $_GET['p'];?></b>
</p>

You need to specify that you are calling $_GET vars. Also make sure to use <?php and not just <?

You need to use $_GET['service'] and $_GET['p'] to get the parameters from the URL:

<b>Personalised
<?
echo $_GET['service'];
?></b>
</p>

<p>Price: &pound;<?
echo $_GET['p'];
?></b>
</p>

As I understand you need to echo parameters passed through url. If so please use $_GET array

<b>Personalised
 <?
echo $_GET['service'];
?></b>
</p>

<p>Price: &pound;<?
echo $_GET['p'];
?></b>
</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM