使用$ _POST时,重定向页面显示为空白

时间:2015-07-27 07:55:51

标签: php

经过一些反复试验,我设法确定了导致问​​题的PHP代码:

  <?php
  if isset($_POST['hoponhopoff']){
  $adults = intval($_POST['bilet_intreg']);
  $price_adults = $adults * 10;
  $children= intval($_POST['bilet_redus']);
  $price_children = $children * 4;
  $free= intval($_POST['bilet_gratis']);
  // Added on 27.07.2015
  $fname= mysqli_real_escape_string($connect, $_POST['fname']);
  $lname= mysqli_real_escape_string($connect, $_POST['lname']);
  $email= mysqli_real_escape_string($connect, $_POST['email']);
  $phone= mysqli_real_escape_string($connect, $_POST['phone']);
  $address= mysqli_real_escape_string($connect, $_POST['address']);
  }
  ?>

我尝试删除条件语句,尝试只使用其中一个变量,尝试没有mysqli_real_escape_string ......似乎没有任何效果。在这部分代码之后有一堆HTML代码,如果删除这些行,它会显示它应该显示的内容。如果我保持不变,那么页面显示为空白而不是显示其内容。有什么想法会发生这种情况吗?

注意:由于我发布的第一个代码中的拼写错误,我更新了代码。结果是一样的,一个空白页。

1 个答案:

答案 0 :(得分:2)

您的代码中存在两个问题。

首先,您的if语句必须包含(),如下所示:if($bool)。因此,您的第一行必须是:

if (isset($_POST['hoponhopoff'])) { // notice the () enclosing the condition

其次,您的$_POST[]函数中的mysqli_real_escape_string()个变量错误了。使用$调用变量,而不是&。因此,您的代码必须如此:

$fname = mysqli_real_escape_string($connect, $_POST['fname']); // notice the $ instead of &
$lname = mysqli_real_escape_string($connect, $_POST['lname']); // notice the $ instead of &
$email = mysqli_real_escape_string($connect, $_POST['email']); // notice the $ instead of &
$phone = mysqli_real_escape_string($connect, $_POST['phone']); // notice the $ instead of &
$address = mysqli_real_escape_string($connect, $_POST['address']); // notice the $ instead of &

&之前使用$var(即&$var)对此变量进行reference