我还在学习php / pdo。我正在对表进行更新。我可以从显示页面中获取特定的行,
$id = $_GET['id'];
$sql = "SELECT * FROM aeroplane WHERE aeroplaneID=:aeroplaneID";
$query = $pdo->prepare($sql);
$query->execute(array(':aeroplaneID' => $id));
while($row = $query->fetch())
{
$aeroplaneName = $row['aeroplaneName'];
$aeroplaneTopSpeed = $row['aeroplaneTopSpeed'];
$aeroplaneRange = $row['aeroplaneRange'];
$planeMakerID = $row['planeMakerID'];
}
但是在尝试更新我得到的行时:
致命错误:带有消息的未捕获异常'PDOException' 'SQLSTATE [HY093]:参数号无效:参数未定义
现在,我已经检查了我传递的参数数量以及它们的名称是否存在错误,或者我的绑定值是否错误?这是我的更新代码:
$sql = "UPDATE aeroplane SET aeroplaneName=:aeroplaneName, aeroplaneTopSpeed=:aeroplaneTopSpeed, aeroplaneRange=:aeroplaneRange, planeMakerID=:planeMakerID WHERE aeroplaneID=:aeroplaneID";
$query = $pdo->prepare($sql);
$query->bindparam(':aeroplaneID', $id);
$query->bindparam(':aeroplaneName', $aeroplaneName);
$query->bindparam(':aeroplaneTopSpeed', $aeroplaneTopSpeed);
$query->bindparam(':aeroplaneRange', $aeroplaneRange);
$query->bindparam(':planeMakerID', $planeMakerid);
$query->execute();
这是发送更新的代码:
<td><input type="hidden" name="id" value=<?php echo $_GET['id'];?></td>
<td><input type="submit" name="update" value="Update"></td>
但不是更新,而是删除行,我的删除代码位于完全不同的页面上。
答案 0 :(得分:0)
有你的错字:
[...] aeroplaneTopSpeed:=aeroplaneTopSpeed [...]
将其更改为=: