【发布时间】:2018-02-25 07:15:36
【问题描述】:
嗨,我正在开发酒店网站。我有一个页面使用 php 和 mysql 在页面中显示所有可用和预订的房间。预订的房间显示为红色背景颜色,带有感叹号按钮。如果我单击带有感叹号的按钮,房间状态应该从已预订变为可用。他的相同功能应该在可用的房间部分完成。可用房间应以绿色背景颜色显示,并带有勾选按钮。如果单击勾选按钮,可用状态应从可用更改为已预订。
这是我的html代码
<?php while($row = mysql_fetch_array($result)):;?>
<div class="w3-small">
<?php if ($row['status'] == 'available'){
echo"<div class='w3-container w3-green w3-text-white w3-padding-small'>
<div class='w3-left'><i class='fa fa-users w3-tiny'></i></div>
<div class='w3-right'>".
"<h3 name='$row[0]'>".$row['roomno']."</h3>".
"</div>".
"<div class='w3-clear'></div>";
echo "<form action='editstatus.php' method='POST'><button class='buttonmark buttoncan' name='available'><i class='fa fa-exclamation-triangle'></i></button></form></div>";
}
elseif ($row['status']== 'booked') {
echo"<div class='w3-container w3-red w3-text-white w3-padding-small'>
<div class='w3-left'><i class='fa fa-users w3-tiny'></i></div>
<div class='w3-right'>".
"<h3 name='$row[0]'>".$row['roomno']."</h3>".
"</div>".
"<div class='w3-clear'></div>";
echo "<form action='editstatus.php' method='POST'><button class='buttonmark buttonok' name='booked'><i class='fa fa-check-square-o'></i></button></form></div>";
}
?>
<br> <br>
</div>
<?php endwhile;?>
我的php代码是
<?php
ob_start(); //After ob_start this output is saved in output buffer, so you can later decide what to do with it.
include("../database/connection.php");
$sql1="UPDATE acroom SET status='$_POST[booked]' WHERE roomno='$row[roomno]'";
// If result matched $myusername and $mypassword, table row must be 1 row
if(mysql_query($sql1)){
header("Location:sample.php");
echo "Records inserted successfully into database.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysql_error($cn);
}
ob_end_flush();
?>
当我运行浏览器时,它显示“记录已成功插入数据库”但数据库尚未更改。 请帮我解决我的问题。
【问题讨论】:
-
您没有发布
roomno值。您永远不会在更新代码中设置$row[roomno]的值。 -
好的先生那我该怎么办先生。我很困惑请指导我
-
如何提交表单值?
-
通过点击按钮先生
标签: php html mysql sql-update imagebutton