如何在php中禁用特定按钮行

时间:2017-10-30 03:10:59

标签: php

如果单击该按钮并且不会影响另一行的按钮,我想在一行中禁用这两个按钮。

我不知道如何禁用表的echo按钮。我想禁用"接受"和"拒绝"按钮,如果其中一个被点击。我提供了一个截图,以便您可以很容易地理解我的意思。提前谢谢。

这是我的PHP代码。它命名为app.php

 <?php

   //connect to database

$con = mysqli_connect('127.0.0.1','root','');

//select database
mysqli_select_db($con, 'appointment');

//select query
$sql = "SELECT * FROM service";

//Execute the query
$records = mysqli_query($con,$sql)

?>
<html>
<head>
<title>Appointment Schedule</title>
</head>

<body>

<table width = "100%" border = "5px" height = "20%">
<tr align = "left">
    <th>First Name</th>
    <th>Middle Name</th>
    <th>Last Name</th>
    <th>Address</th>
    <th>Date</th>
    <th>Time</th>
    <th>Office</th>
    <th>Service</th>
    <th>Contact No.</th>
    <th>Remarks</th>
</tr>
<?php
while($row = mysqli_fetch_array($records))
{
    echo "<tr><form action = 'display.php' method = post>";
    echo "<input type=hidden name=id value='".$row['ID']."'>";
    echo "<td>".$row['fname']."</td>";
    echo "<td>".$row['mname']."</td>";
    echo "<td>".$row['lname']."</td>";
    echo "<td>".$row['address']."</td>";
    echo "<td>".$row['date']."</td>";
    echo "<td>".$row['time']."</td>";
    echo "<td>".$row['office']."</td>";
    echo "<td>".$row['services']."</td>";
    echo "<td><name = number>".$row['contactno']."</td>";
    echo "<td>".$row['remarks']."</td>";
    echo "<td><input type =submit value='Accepted' name=accept>";
    echo "<td><input type =submit value='Rejected' name=reject>";
    echo "</form></tr>";    
}
?>

</table>
</body>
</html>

这是我的另一个PHP代码。它命名为display.php

<?php

//connect to database

$con = mysqli_connect('127.0.0.1','root','');

//select database
mysqli_select_db($con, 'appointment');

if($_POST['accept'])
{
$sql = "UPDATE service SET remarks = 'Accepted' WHERE ID=$_POST[id]";

}

else if($_POST['reject'])
{
$sql = "UPDATE service SET remarks = 'Rejected' WHERE ID=$_POST[id]";
}

//Execute Query
if(mysqli_query($con,$sql))
    header("refresh:1; url=app.php");
else
    echo "Unsuccessful";
?>

这是我工作的屏幕截图

Sample of my database table using php

sample db table

1 个答案:

答案 0 :(得分:0)

请尝试以下代码: 提供显示按钮的条件

echo "<td><input type =submit value='Accepted' name=accept>";
echo "<td><input type =submit value='Rejected' name=reject>";
if($row['remarks'] == 'Accepted' || $row['remarks'] == 'Rejected')
{
    echo "<td><input type =submit disabled value='Accepted' name=accept>";
    echo "<td><input type =submit disabled value='Rejected' name=reject>";
}
相关问题