php验证表3

时间:2017-04-05 09:55:36

标签: php mysql

db.php中     

// databse connection

$pdoConnect = new PDO("mysql:host=localhost:3307;dbname=project", "root", "usbw");
$pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);




if (isset($_POST['update'])) {
    $id = $_POST['id'];
    $issue = $_POST['issue'];
    $content = $_POST['content'];
    $contact = $_POST['contact'];
    echo "Successful";
    $pdoQuery = "UPDATE `checks` set `issue`=:issue, `content`=:content, `contact`=:contact WHERE `id` = :id";

    $pdoResult = $pdoConnect->prepare($pdoQuery);

    $pdoExec = $pdoResult->execute(array(":issue" => $issue, ":content" => $content, ":contact" => $contact, ":id" => $id,));


    if (!empty($_POST)) {
        header("Location: ListIssueCheck.php");
        exit;
    } else {
        echo 'Data not Updated';
    }
}


模态表单Update.php

<td><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal">Update</button></td>
<td><div id="myModal" class="modal fade" role="dialog">
        <div class="modal-dialog">


            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Update Issue</h4>
                </div>

                <div class="modal-body">
                    <p><form class="form-horizontal" action="UpdateI.php" method="post">
                        <div class="form-group">
                            <label for="formGroupExampleInput">ID</label>
                            <input type="number" class="form-control" id="formGroupExampleInput" name="id" required>
                        </div>
                        <div class="form-group">
                            <label for="formGroupExampleInput2">Title</label>
                            <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" name="title">
                        </div>
                        <div class="form-group">
                            <label for="formGroupExampleInput2">Text</label>
                            <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input" name="text">
                        </div>
                            <div class="form-group">
                                <label for="formGroupExampleInput2">createtime</label>
                                <input type="date" class="form-control" id="formGroupExampleInput2" placeholder="Another input" name="createtime">
                            </div>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn-default" name="update" id="submit">Submit</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                    </form>
                </div>
            </div></td>

  1. 如何验证缺少的ID以检查它是否为空。
  2. 点击提交后如何显示成功更新消息?

1 个答案:

答案 0 :(得分:0)

本教程可能对您有所帮助。它包含了php的所有必要验证技术。https://www.tutorialspoint.com/php/php_validation_example.htm