我正在尝试使用pdo来更新数据库,代码没有返回任何错误,但代码不起作用。 逻辑是用户输入用户ID,然后新位置点击提交,位置将更新。
以下是表单代码:
<html>
<head>
<title>Web Dev 1</title>
</head>
<body>
<form method="post" action="update.php">
Patient location by ID: <input type="text" id="Patid" name="Patid" /><br />
Location: <input type="text" id="Location" name="Location" /><br />
<input type="submit" name = 'action' value="update" />
</html>
这是更新代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$host = "localhost";
$user ="sbuser";
$db = "mdb";
$pass ="lamepassword";
$conn = new PDO($dsn, $user, $password);
$sqlInsert = 'UPDATE lobby set Location=:Location where Patid=:Patid';
$preparedStatement = $conn->prepare($sqlInsert);
$preparedStatement->execute(array(':Patid' => '$_POST[Patid]', ':Location' = $_POST[Location]' );
}
?>
答案 0 :(得分:2)
您的代码中存在一些错误
<?php
$host = "localhost";
$db = "mdb";
$user ="sbuser";
$pass ="";
$Patid=$_POST['Patid'];
$Location=$_POST['Location'];
$conn = new PDO("mysql:host=$host;name=$name",$user,$pass);
$sqlInsert = "UPDATE lobby SET Location=? WHERE Patid=?";
$preparedStatement = $conn->prepare($sqlInsert);
$preparedStatement->execute(array($Location, $Patid));
?>