为什么此页面无法添加数字和重定向?

时间:2016-07-23 21:35:25

标签: php mysql prepared-statement

所以基本上我有另一个页面通过GET向这个页面发送信息。我仔细检查了URL以确保GET正常工作,它就是这样。我不明白的是为什么这个剧本不会:

1)在管理表...中添加一个NumberOfResponse ...

2)重定向到页面(参见代码底部)

现在,呼叫状态更新为2,但没有其他任何事情发生,或者是否有任何回声。

代码

<?php
session_start();

include '../includes/connection.php';
include 'functions.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);


$id = escape($_GET['id']);
$banner = escape($_GET['bannerID']);
$bannerName = escape($_GET['bannerN']);

$query = $handler->prepare("UPDATE Calls SET Status = '2', TakenBy = :bannerName WHERE ID=:id");
$query->bindParam(':bannerName', $bannerName);
$query->bindParam(':id', $id);
$query->execute();

$update = $handler->prepare("UPDATE Admins SET NumOfResponse + 1 WHERE ID = :banner");
$update->bindParam(':banner', $banner);
$update->execute();

header("Location: ../pages/incomingCalls.php");

2 个答案:

答案 0 :(得分:1)

我认为你不需要选择NumOfResponse来在第二个查询中更新它的值。您可以通过执行单个更新查询来实现此目的。

此外,你在做一些奇怪的事情:

$query = $query->fetchObject();

您不需要获取更新查询的结果。

另一个错误是你做的时候:

$number = $query->NumOfResponse;

您实际上是用另一个值覆盖已经增加的值$ number。

您可以像这样简化代码:

<?php
session_start();

include '../includes/connection.php';
include 'functions.php';

$id = escape($_GET['id']);
$banner = escape($_GET['bannerID']);
$bannerName = escape($_GET['bannerN']);

$query = $handler->prepare("UPDATE Calls SET Status = '2', TakenBy = :bannerName WHERE ID=:id");
$query->bindParam(':bannerName', $bannerName);
$query->bindParam(':id', $id);
$query->execute();

$update = $handler->prepare("UPDATE Admins SET NumOfResponse = NumOfResponse  + 1 WHERE ID = :banner");
$update->bindParam(':newNum', $newNum);
$update->bindParam(':banner', $banner);
$update->execute();

header("Location: ../pages/incomingCalls.php");

答案 1 :(得分:0)

因为你在标题指令之前做回声。 在打印任何内容之前,您必须先添加标题值。删除回声或使用日志框架,如log4php。