我正在制作一个表格来更新我的MySQL数据库,但由于某种原因,我在浏览器中收到以下错误:
C:\wamp\www\Helpdeskapplicatie\update_hardware.php on line 49
有人能告诉我我做错了吗?
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/layout.css"/>
</head>
<body>
<div id="menu">
<div id="menu_wrapper">
<ul>
<li>Configuratiebeheer<img src="afb/pijltje.png" width="10"/></a>
<ul>
<li><a href="configuratiebeheer_hardware.php">Lijst hardware</a></li>
<li><a href="hardware_toevoegen.php">Hardware toevoegen</a></li>
<li><a href="hardware_verwijderen.php">Hardware verwijderen</a></li>
</ul>
</li>
</ul>
</div>
</div>
<?php
$connect=mysql_connect("localhost", "root","");
mysql_select_db("helpdesk_middenpolder", $connect);
$id=$_GET['id'];
$q="SELECT * FROM hardware WHERE hardwareID=$id";
$r=mysql_query($q);
echo "<table border='1'>";
echo "<th>merknaam</th><th>producttype</th><th>hardwaretype</th>";
while ($x=mysql_fetch_array($r)){
echo "<tr>";
echo "<td>";
echo "<input type='text' value='".$x['merknaam']."'>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='".$x['producttype']."'>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='".$x['hardwaretype']."'>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($connect);
?>
<?php
if(isset($_POST['updatehardware'])){
$query = "UPDATE hardware SET merknaam='".$x['merknaam']."', producttype='".$x['producttype']."', hardwaretype='".$x['hardwaretype']."' WHERE hardwareID='".$id['id']."'";
mysql_query($query);
}
?>
<form method="post">
<input type="submit" name="updatehardware" value="Hardware updaten">
</form>
</body>
</html>
答案 0 :(得分:2)
您的更新查询需要像这样更改
hardwareID='".$id."'
而不是
hardwareID='".$id['id']."'
答案 1 :(得分:0)
您使用$id['id']
代替$_GET['id']
。但是从不信任传递GET / POST数据。改为使用:
$id = (int) $_GET['id'];