简体   繁体   中英

PDO Request Causing 500 Internal Server Error

This PDO request is not welcomed by my server for some reason. It makes the server throw a 500 Internal Server Error. All of my other PHP files are working fine and I haven't changed any server settings. Strangely though, It seems that when I comment out the line that binds the variable $u, it does not give a 500 error. I am perplexed.

<?php

$u=$_GET["u"];

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$amount = isset($_POST['amount']) ? $_POST['amount'] : null;
if (null != $amount) {

$user = 'username';
$pass = 'password';
$pdo = new PDO('mysql:host=localhost', $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
session_start();
$tablename = $_SESSION['MM_Username'];
$query = sprintf("UPDATE `%s` SET `stock` = :amount WHERE `itemname` = :u", $tablename);
$stmt = $pdo->prepare($query);
$stmt->bindParam('u', $u);
$stmt->bindParam('amount', $amount);
$stmt->execute();
}
}

?>

您的错误日志中将显示一条错误消息,告诉您您的问题。

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