php - 需要行 ID,以便在未收到状态时不允许用户单击它

标签 php mysql pdo

我试图获取它,以便当行“状态”显示“已完成”或“进行中”时,记录不允许用户更新。不知道如何实现这一点。基本上,只有当行状态 = 已接收时,他们才能单击链接到 update_id.php 的 id。如果已完成或正在进行中,他们会弹出一个框,显示自定义错误消息。我正在寻找示例或教程。

  <?php

        require_once 'db_connect.php';
        $conn = dbConnect();
        $OK = true; // We use this to verify the status of the update.
        if (isset($_GET['id'])) {
            // Create the query
            $data = "%".$_GET['id']."%";
            $sql = 'SELECT * FROM requests WHERE id like ?';
            $stmt = $conn->prepare($sql);
            $results = $stmt->execute(array($data));
            $rows = $stmt->fetchAll();
            $error = $stmt->errorInfo();
            //echo $error[2];
        }
        // If there are no records.
        if(empty($rows)) {
            echo "<tr>";
                echo "<td colspan='4'>There were not records</td>";
            echo "</tr>";
        }
        else {
            foreach ($rows as $row) {
                echo "<tr>";
                    $id = $row['id'];
                    echo "<td><a href='update_Id.php?id=$id'>$id</a></td>";
                    echo "<td>".$row['name']."</td>";
                    echo "<td>".$row['lanId']."</td>";
                    echo "<td>".$row['department']."</td>";
                    echo "<td>".$row['mgrname']."</td>";
                    echo "<td>".$row['work_requested']."</td>";
                    echo "<td>".$row['purchase_order']."</td>";
                    echo "<td>".$row['inbound_shipment']."</td>";
                    echo "<td>".$row['status']."</td>";
                    echo "<td>".$row['request_comments']."</td>";


                echo "</tr>";
            }
        }
    ?>

更新页面

<?php
    include('../db_connect.php');
    include('../functions/functions.php');
    $id=$_GET['id'];
    $result = $db->prepare("SELECT * FROM requests WHERE id= :id");
    $result->bindParam(':id', $id);
    $result->execute();
    for($i=0; $row = $result->fetch(); $i++){
?>

<html>
<head>
<script type="text/javascript" src="Javascript/textboxname_autocomplete2.js"></script>

<title></title>

<style type="text/css">

}
.body{
    background-color: #F2F2F2;
    border: thin solid #666666;
}
</style>

</head>
<body class='body'>
<form action = "update_Id_Process.php"  method ="post" class="Form">

<p><input type ="hidden" name = "id" value="<?php echo($id); ?>"</p>

<h2 align="center">Edit request  Information</h2>
<table border='1' align="center" style="width: 582px">

<tr>    
    <td>Employee Name:</td>
<td><input type="text" value ="<?php  echo($row['name']) ?>"name="name"></td>

    <td>Manager Name</td>
<td style="width: 175px">
<input type="text" value ="<?php  echo($row['mgrname']) ?>"name="mgrname" style="width: 162px"></td>
</tr>


<tr>    
    <td>Employee Lan Id:</td>
<td><input type="text" value ="<?php  echo($row['lanId']) ?>"name="lanId"></td>

    <td>Manger_LanId</td>
<td style="width: 175px">
<input type="text" value ="<?php  echo($row['mgrLanId']) ?>"name="mgrLanId" style="width: 162px"></td>
</tr>

<tr>    
    <td>Department Location</td>
<td><input type="text" value ="<?php  echo($row['department']) ?>"name="department"></td>

    <td>PO</td>
<td style="width: 175px">
<input type="text" value ="<?php  echo($row['purchase_order']) ?>"name="purchase_order" style="width: 162px"></td>
</tr>


<tr>    
    <td>Work Requested</td>
<td><input type="text" value ="<?php  echo($row['work_requested']) ?>"name="work_requested"></td>
    <td>IS</td>
<td style="width: 175px">
<input type="text" value ="<?php  echo($row['inbound_shipment']) ?>"name="inbound_shipment" style="width: 162px"></td>
</tr>

</table>
<h2 align='center'>Requested Comments</h2>
<table border='1' align="center">


<tr>    

<td width='400'  height="40">
<textarea name="request_comments"  style="width: 600px; height: 81px" style="text-transform:uppercase ;"><?php echo $row['request_comments']; ?></textarea></td>

</tr>

</table>
<input type="hidden" value ="<?php  echo($row['status']) ?>"name="status">
<input type="hidden" value ="<?php  echo($row['comments']) ?>"name="comments">
<input type="hidden" value ="<?php  echo($row['compUser']) ?>"name="compUser">
<input type="hidden" value ="<?php  echo($row['compDt']) ?>"name="compDt">
    <br>
<div align="center">    
<input type="submit" value= "Update Information">
<br>
</div>
</form>


</body>
</html>
<?php
    }
?>

最佳答案

如果单词“completed”或“In_progress”被发回更新页面的文本框中,我可以创建一个 JavaScript 来禁用该按钮。它还会提醒用户,如果状态文本框未显示“已收到”,他们将无法更新。

这是经过修改的更新页面,供其他人查看其完成情况。

 <?php
            include('../db_connect.php');
            include('../functions/functions.php');
            $id=$_GET['id'];
            $result = $db->prepare("SELECT * FROM requests WHERE id= :id");
            $result->bindParam(':id', $id);
            $result->execute();
            for($i=0; $row = $result->fetch(); $i++){
        ?>

        <html>
        <head>
        <script type="text/javascript" src="Javascript/textboxname_autocomplete2.js"></script>

        <title></title>

        <style type="text/css">

        }
        .body{
            background-color: #F2F2F2;
            border: thin solid #666666;
        }

        </style>


        <script type="text/javascript">

        function NoWord(el){

        var subb=document.forms[0].elements["status"].value;

        if(subb=="Completed" || subb=="In_Progress")
        {
        alert("Can only update request when in Received Status");
        document.forms[0].elements["button1"].disabled="disabled"
        window.location.href="http://google.com";
            return false;

        }

        return true;
        }

        </script>

        </head>
        <body class='body'>
        <form name="myForm" action="update_Id_Process.php"  method="post" class="Form" onsubmit="return NoWord(this.name);">

        <p><input type ="hidden" name = "id" value="<?php echo($id); ?>"</p>

        <h2 align="center">Edit request  Information</h2>
        <table border='1' align="center" style="width: 582px">

        <tr>    
            <td>Employee Name:</td>
        <td><input type="text" value ="<?php  echo($row['name']) ?>"name="name"></td>

            <td>Manager Name</td>
        <td style="width: 175px">
        <input type="text" value ="<?php  echo($row['mgrname']) ?>"name="mgrname" style="width: 162px"></td>
        </tr>


        <tr>    
            <td>Employee Lan Id:</td>
        <td><input type="text" value ="<?php  echo($row['lanId']) ?>"name="lanId"></td>

            <td>Manger_LanId</td>
        <td style="width: 175px">
        <input type="text" value ="<?php  echo($row['mgrLanId']) ?>"name="mgrLanId" style="width: 162px"></td>
        </tr>

        <tr>    
            <td>Department Location</td>
        <td><input type="text" value ="<?php  echo($row['department']) ?>"name="department"></td>

            <td>PO</td>
        <td style="width: 175px">
        <input type="text" value ="<?php  echo($row['purchase_order']) ?>"name="purchase_order" style="width: 162px"></td>
        </tr>


        <tr>    
            <td>Work Requested</td>
        <td><input type="text" value ="<?php  echo($row['work_requested']) ?>"name="work_requested"></td>
            <td>IS</td>
        <td style="width: 175px">
        <input type="text" value ="<?php  echo($row['inbound_shipment']) ?>"name="inbound_shipment" style="width: 162px"></td>
        </tr>
        <tr>    
            <td>Status</td>
        <td><input type="text" value ="<?php  echo($row['status']) ?>" id="status"  name="status"></td>
            <td></td>
        <td style="width: 175px"></td>
        </tr>
        </table>
        <h2 align='center'>Requested Comments</h2>
        <table border='1' align="center">


        <tr>    

        <td width='400'  height="40">
        <textarea name="request_comments"  style="width: 600px; height: 81px" style="text-transform:uppercase ;"><?php echo $row['request_comments']; ?></textarea></td>

        </tr>

        </table>

        <input type="hidden" value ="<?php  echo($row['comments']) ?>" name="comments">
        <input type="hidden" value ="<?php  echo($row['compUser']) ?>" name="compUser">
        <input type="hidden" value ="<?php  echo($row['compDt']) ?>" name="compDt">
            <br>

        <div align="center"><input type="submit" value="Update Information" name="button1"></dv>

        </form>


        </body>
        </html>
        <?php
            }
        ?>

关于php - 需要行 ID,以便在未收到状态时不允许用户单击它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27001813/

相关文章:

php - Opencart pavblog 最新模块 - 从特定类别中获取最新模块

php - 使用 XPath 和 PHP 解析 HTML

php - 是否可以让PDO忽略无效参数号异常?

PHP PDO - 没有事件事务

php - 从数据库构建树

php - 锁定远程目录但不锁定 URL

mysql - 如何存储整个网页供以后解析?

MySQL 查询所有尚未关注或尚未刷卡的用户

php - 无法使用 PDO/PHP 获取最后插入的 UUID

php - 用php将16张图片合并成1张大图片