1

私はカスタマイズされた CMS に取り組んでおり、PHP に関するいくつかのことを学ぼうとしています。私は自分の経験を、私が見たり読んだりしたいくつかのチュートリアルに基づいています。

page_hemそこで、すべてのデータが保存されるこのテーブルを呼び出します。次に、当面は index.php であるページ全体のテキスト フィールドにエコーします。特にphpMyAdminからデータを挿入すると、すべて正常に動作します。

しかし、今は編集フォームを作成していますが、うまくいきません。すべてをテキスト ボックスにエコーできるので、テキストを変更できますが、「保存」ボタンを押しても、成功メッセージが表示されても、変数がデータベースで更新されません。問題が編集ページにあるのか解析コードにあるのかはわかりません。Firebugging を行っている場合でも、エラーは発生しません。

編集ページは次のとおりです。

<?php
require_once "../scripts/connect_to_mysql.php";
// Determine which page ID to use in our query below 

if (!$_GET['pid']) {
    $pageid = '1';
} else {
    $pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}

// Query the body section for the proper page
$sqlCommand = "SELECT text1, text2 FROM page_hem WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $body1 = $row["text1"];
    $body2 = $row["text2"];
} 
mysqli_free_result($query); 
?>
<!DOCTYPE html>

<head>
    <meta charset="UTF-8">

</head>

<body>

<div class="container">

<div class="home-page main">
    <section class="grid-wrap" >
        <header class="grid col-full">
            <hr>

        <form id="form" name="form" method="post" action="page_edit_parse.php">

        <div class="grid col-two-thirds mq2-col-full">
            <label>Titel:</label>
            <textarea name="body1" id="body1" cols="3" rows="2"><?php echo $body1 ?></textarea>
            <label>Meddelande</label>
            <p><textarea name="body2" id="body2" cols="6" rows="10"><?php echo $body2 ?></textarea></p><br>
        </div>


         <input type="submit" name="button" id="button" value="Update!" />
    </form>

    </section>
</body>
</html>

そして、ここに page_edit_parse.php があります

<?php
// You may want to obtain refering site name that this post came from for security purposes here
// exit the script if it is not from your site and script
    $body1 = $_POST["text1"];
    $body2 = $_POST["text2"];

include_once "../scripts/connect_to_mysql.php";
// Add the updated info into the database table
$query = mysqli_query($myConnection, "UPDATE page_hem SET text1='$body1', text2='$body2', lastmodified='now()' WHERE id='$pid'") or die (mysqli_error($myConnection));

echo 'Updated, yeah! <br /><br /><a href="kpanel.php">Go back!</a>';
exit();
?>

PS: HTML を編集したため、短いエラーが発生する可能性があります。

4

1 に答える 1