room.php
<input name = "room" type = "text" size="70"/>
<a href="updateroom.php?roomid=<?=$row_Recordsetroomid['roomid'] ?>">Update</a>
updateroom.php
<?php
mysql_connect('localhost','athirahhazira','1234');
mysql_select_db("dbcollege");
session_start();
$sql = "UPDATE studentsroom set room='$strroom' WHERE roomid='$_GET[roomid]'";
mysql_query($sql) or die('Error updating room status');
header('Location:staff/room-staff.php');
?>
如果有默认值,我可以更新,例如:
$sql = "UPDATE studentsroom set room='A206' WHERE roomid='$_GET[roomid]'";
但不是文本框中的值。你能帮我解决我在这里失踪的事情吗?
答案 0 :(得分:1)
试试这个
$sql = "UPDATE studentsroom set room='A206' WHERE roomid='".$_REQUEST['roomid']."'";
注意:你的代码可以是sql注入。使用mysql_*
或mysqli_*
PDO
更新2:
添加表单并提交按钮而不是超链接
<form method="post" action="updateroom.php" >
<input name = "room" type = "text" size="70"/>
<input type="hidden" name="roomid" value="<?php echo $row_Recordsetroomid['roomid'];?>" />
<input type="submit" name="submit" value="Update" />
</form>
AND update.php
<?php
mysql_connect('localhost','athirahhazira','1234');
mysql_select_db("dbcollege");
session_start();
$room = $_REQUEST['room'];
$roomid = $_REQUEST['roomid'];
$room = mysql_real_escape_string($room);
$roomid = mysql_real_escape_string($roomid);
$sql = "UPDATE studentsroom set room='$room' WHERE roomid='$roomid'";
mysql_query($sql) or die('Error updating room status');
header('Location:staff/room-staff.php');
?>
答案 1 :(得分:1)
缺少$_GET
中索引的引号。在大多数情况下,尝试访问$array[key]
而不是$array['key']
等数组变量会触发错误。因此,请始终尝试使用数组索引的引号。
你可以试试这个。
$sql = "UPDATE studentsroom set room='A206' WHERE roomid='".$_GET['roomid']."'";