如何调试UPDATE函数在PHP中无法正常工作的原因?

时间:2022-09-18 12:39:21

I am working on a customized CMS to try to learn some stuff on PHP. I am basing my experience in some tutorials I see/read.

我正在开发一个定制的CMS,试图学习PHP的一些东西。我的经验基于我看到/阅读的一些教程。

So, I have this table called page_hem where all the data is saved. Then I have it echoing on text fields all over the page that is for the time being my index.php. All works fine, especially if I insert the data from the phpMyAdmin.

所以,我有一个名为page_hem的表,其中保存了所有数据。然后我让它在整个页面上的文本字段上回显,暂时是我的index.php。一切正常,特别是如果我从phpMyAdmin插入数据。

But now I am creating the edit form and things are not working any more. I can still echo everything into text boxes so I can change the text but when I press the button "save" my variables don't update on the database despite I get the success message. I don't know if the issue is on the edit page or on the parse code; I don't get any errors, even when I am Firebugging.

但现在我正在创建编辑表单,事情不再有效。我仍然可以将所有内容回显到文本框中,以便我可以更改文本,但是当我按下“保存”按钮时,我的变量不会在数据库上更新,尽管我得到了成功消息。我不知道问题是在编辑页面上还是在解析代码上;即使我是Firebugging,我也不会有任何错误。

Here is the edit page:

这是编辑页面:

<?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>

And here is the page_edit_parse.php

这是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: There might be some minor errors on the html due to I edited it so it would be shorter.

PS:html可能会有一些小错误,因为我编辑它会缩短。

1 个解决方案

#1


0  

You have error in your select query:

您的选择查询中有错误:

SELECT text1, text2, FROM page_hem WHERE id='$pageid' LIMIT 1
                 ^^^ here remove the semicolon

#1


0  

You have error in your select query:

您的选择查询中有错误:

SELECT text1, text2, FROM page_hem WHERE id='$pageid' LIMIT 1
                 ^^^ here remove the semicolon