首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何调试为什么更新函数在PHP中不起作用?

如何调试为什么更新函数在PHP中不起作用?
EN

Stack Overflow用户
提问于 2013-09-25 17:27:38
回答 1查看 290关注 0票数 1

我在一个定制的CMS上工作,试图学习一些关于PHP的东西。我将我的经验建立在我看到/读到的一些教程中。

因此,我有一个名为page_hem的表,其中保存了所有数据。然后,我让它在整个页面的文本字段中回显,目前我的index.php也是如此。一切正常,特别是当我插入来自phpMyAdmin的数据时。

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

这里是编辑页面:

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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上可能有一些小错误,因为我对它进行了编辑,所以它会更短。

EN

回答 1

Stack Overflow用户

发布于 2013-09-25 17:31:57

您的select查询有错误:

代码语言:javascript
复制
SELECT text1, text2, FROM page_hem WHERE id='$pageid' LIMIT 1
                 ^^^ here remove the semicolon
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19001109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档