[英]updating a field in mysql using php
|room type|price|avroom|
|standard |50 |20 |
| super |60 | 7 |
|suite |80 | 4 |
if reservation is made for "room type" = standard the value entered in the "no of rooms" field in the form should be subtracted from the value in the "avroom" for the "room type" on the database 如果为“房间类型” =标准进行预订,则应从数据库中“房间类型”的“ avroom”中的值中减去在表格的“无房间”字段中输入的值
the code below outputs the form 下面的代码输出表格
</select></td>
<th align=left>ROOM TYPE :</th>
<td>
<?php
echo "<select name=txttype>";
$qup="select * from tariff where avroom > 0";
$rs=mysql_query($qup);
while($res=mysql_fetch_row($rs))
{
echo "<option value='".$res[0]."'>".$res[0]."</option>";
}
echo "<select>";
echo "</td>";
?>
<tr>
<th align=left>NO OF ROOMS :</th>
<td><select name=txtroom>
<?php
for($i=1;$i<=20;$i++)
{
echo "<option value=$i>$i</option>";
}
?>
please if you need any more info let me know 请如果您需要更多信息,请告诉我
First thing I noticed in your mysql table is there cannot have a column like "room type" in a table. 我在您的mysql表中注意到的第一件事是表中不能有类似“ room type”的列。 It should be edited to "room_type".
应该将其编辑为“ room_type”。
First of all, if you only need to display the room type in the top select box, your sql should be edited to $qup="select room_type from tariff where avroom > 0";
首先,如果只需要在顶部选择框中显示房间类型,则应将sql编辑为
$qup="select room_type from tariff where avroom > 0";
. 。 Then post the selected values using a html form.
然后使用html表单发布选定的值。
From the other end where the form is posted, try something like, 从发布表单的另一端尝试类似的方法,
$room_type= $_POST['txttype'];
$rooms = mysql_real_escape_string($_POST['txtroom']);
if($room_type == "standard")
{
$query = "UPDATE tariff SET avroom=avroom-{$rooms} WHERE room_type='standard'";
// Now execute the above query here.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.