我不知道我的代码有什么问题。有点新的PHP
这是我的HTML代码
<html>
<body>
<form action="sample2.php" method="POST">
<input type="submit" value="occupied" id="occupied">
<input type="submit" value="reserved" id="reserved">
<a name="slot1" style="background-color: green; width:100px; height:100px; border-top-right-radius:0px; border: 2px
solid Black;float:left; position:absolute; top:400px; left:441px;">
</form>
</body>
</html>
PHP代码在这里
<?php
$con=mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample");
if(isset($_POST['occupied'])){
$query="UPDATE reservation SET status='occupied' where status='vacant'";
echo "<a style=background-color: red; width:100px; height:100px; border-top-right-radius:0px; border: 2px
solid Black;float:left; position:absolute; top:400px; left:441px;>";
}
?>
我的问题是每当我点击占用的按钮时,盒子的颜色都不会从绿色变为红色,它只会将我引导到空白页面。帮助
答案 0 :(得分:2)
试试这个:
<input type="submit" value="occupied" name="occupied">
<input type="submit" value="reserved" name="reserved">
表单提交带有“名称”的控件,由于这些控件没有name属性,因此它们不会提交给您的PHP脚本。
了解Successful Controls了解详情。
答案 1 :(得分:1)
你必须将id和名称放在一起,如下所示:
<html>
<body>
<form action="sample2.php" method="POST">
<input type="submit" value="occupied" id="occupied" name="occupied">
<input type="submit" value="reserved" id="reserved" name="reserved">
<a name="slot1" style="background-color: green; width:100px; height:100px; border-top-right-radius:0px; border: 2px
solid Black;float:left; position:absolute; top:400px; left:441px;"></a>
</form>
</body>
</html>