-1

こんにちは、この更新を完了しようとしていますが、エラーのない空白のページが送信され続け、情報がデータベースに送信されません。私が知る限り、準備されたステートメントのポイントまですべてが機能します.IDと他の変数はデータベースと以前の検索クエリから問題なく描画されますが、それ以上先に進むことはできません. どこが間違っているのか、誰にもわかりませんか?

<html>
                    <head>
                            <title>
                                <?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?>
                            </title>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                    </head>

                    <body>
                            <h1><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>
                            <?php if ($error != '') {
                                    echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error
                                            . "</div>";
                            } ?>

                            <form action="" method="post">
                            <div>
                                    <?php if ($id != '') { ?>
                                            <input type="hidden" name="id" value="<?php echo $id; ?>" />
                                            <p>ID: <?php echo $id; ?></p>
                                    <?php } ?>

                                    <br><strong>Item Type: *  </strong><input name="item_type" value="<?php echo $item_type; ?>" type="text"><br>
                                    <br><strong>Location: *  </strong><input name="location" value="<?php echo $location; ?>" type="text"><br>
                                    <br><strong>Date Last Test: * </strong><input name="date_last_test" value="<?php echo $date_last_test; ?>" type="date"><br>
                                    <br><strong>Serial Number: *</strong><input name="serial_number" value="<?php echo $serial_number; ?>" type="text"><br>
                                    <br><strong>Date Next Test: *</strong><input name="date_next_test" value="<?php echo $date_next_test; ?>" type="date"><br>
                                    <br><strong>Comments: *</strong><input name="comments" value="<?php echo $comments; ?>" type="text"><br>

                                    <p style="text-align: left;">* required</p>
                                    <input name="submit" value="Submit" type="submit"><div style="text-align: left;">
                            </div></div><div style="text-align: left;">
                        </body>
                </html>

    /*

       EDIT RECORD

    */
    // if the 'id' variable is set in the URL, we know that we need to edit a record
    if (isset($_GET['id']))
    {
            // if the form's submit button is clicked, we need to process the form
            if (isset($_POST['submit']))
            {
                    // make sure the 'id' in the URL is valid
                    if (is_numeric($_POST['id']))
                    {
                            // get variables from the URL/form
                            $id = $_POST['id'];
                            $item_type = htmlentities($_POST['item_type'], ENT_QUOTES);
                            $location = htmlentities($_POST['location'], ENT_QUOTES);
                            $date_last_test = htmlentities($_POST['date_last_test'], ENT_QUOTES);
                            $serial_number = htmlentities($_POST['serial_number'], ENT_QUOTES);
                            $date_next_test = htmlentities($_POST['date_next_test'], ENT_QUOTES);
                            $comments = htmlentities($_POST['comments'], ENT_QUOTES);


                            // check that firstname and lastname are both not empty
                            if ($item_type == '' || $location == ''|| $date_last_test == ''|| $serial_number == ''|| $date_next_test == ''|| $comments == '' )
                            {
                                    // if they are empty, show an error message and display the form
                                    $error = 'ERROR: Please fill in all required fields!';
                                    renderForm($item_type, $location, $date_last_test, $serial_number, $date_next_test, $comments, $error, $id);
                            }
                            else
                            {
                                    // if everything is fine, update the record in the database
                                            if ($stmt = $mysqli->prepare("UPDATE `Calibration_and_Inspection_Register` SET `item_type` = ?, `location` = ?, `date_last_test` = ?, `serial_number` = ?, `date_next_test` = ?, `comments` = ?
                                            WHERE `id`=?"))
                                    {
                                            $stmt->bind_param("issdsds",`$id`, `$item_type`, `$location`, `$date_last_test`, `$serial_number`, `$date_next_test`, `$comments`);
                                            $stmt->execute();
                                            $stmt->close();
                                    }

                                    // show an error message if the query has an error
                                    else
                                    {
                                            echo "ERROR: could not prepare SQL statement.";
                                    }
                                    // redirect the user once the form is updated
                                    //header("Location: View Calibration and Inspection records.php");
                            }        
                    }
                   // if the 'id' variable is not valid, show an error message
                    else
                    {
                            echo "Error with ID !";
                    }
            }
            // if the form hasn't been submitted yet, get the info from the database and show the form
            else
            {
                    // make sure the 'id' value is valid
                    if (is_numeric($_GET['id']) && $_GET['id'] > 0)
                    {
                            // get 'id' from URL
                            $id = $_GET['id'];

                            // get the recod from the database
                            if($stmt = $mysqli->prepare("SELECT `item_type`,`location`,`date_last_test`,`serial_number`,`date_next_test`,`comments`,`id` FROM `Calibration_and_Inspection_Register` WHERE id=?"))
                            {
                                    $stmt->bind_param("i", $id);
                                    $stmt->execute();

                                    $stmt->bind_result($item_type, $location, $date_last_test, $serial_number, $date_next_test, $comments, $id);
                                    $stmt->fetch();

                                    // show the form
                                    renderForm($item_type, $location, $date_last_test, $serial_number, $date_next_test, $comments, $id);

                                    $stmt->close();
                            }
                            // show an error if the query has an error
                            else
                            {
                                   echo "Error: could not prepare SQL statement";
                            }
                    }
                 // if the 'id' value is not valid, redirect the user back to the view.php page
                   else
                    {
                           header("Location: View All Calibration and Inspection Records.php");
                    }
            }
    }
4

2 に答える 2

3

すべてのエラーを表示すると、役立つ場合があります

追加

error_reporting(E_ALL);
ini_set( 'display_errors','1'); 

あなたのphpページの一番上に...

さらに、よくわかりませんが、これは私には正しく見えません..

header("Location: View All Calibration and Inspection Records.php");

少なくとも

header("Location: viewallcalibrationandinspectionrecords.php");
于 2013-09-28T01:41:52.680 に答える
1

1年経った今、この質問を振り返ってみると、私が何を間違えたのかが正確にわかります。という形で、私は何のアクションも与えず、そのままにしておきました<form action="" method="post">。だったはず<form action="#" method="post">です。初心者による基本的なもの。

于 2014-09-24T06:30:57.100 に答える