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. 仅在我的文本框中验证数字和字母
  2. php,检查文本拆分的正确性
  3. 如何使用Ajax或Jquery填充文本框中的值?
  4. 当excel表格单元格的格式是日期格式非文本格式的时候,phpexcel 应
  5. 从文本文件中读取,然后决定是否要在php中禁用或启用按钮
  6. 有没有办法阻止使用类似Firebug的工具在页面中编辑HTML和CSS内容
  7. 可以使用不同文本框编辑的不同弹出窗口?
  8. 从文本框值生成条形码图像
  9. ASP.NET文本框不会失去焦点

随机推荐

  1. Android官方架构组件DataBinding双向绑定
  2. Android 界面编程
  3. Android 设置颜色的方法总结
  4. Android Studio设置国内镜像网站
  5. Android触摸事件分发机制
  6. Android 系统framework 概述
  7. Android上的Notification
  8. Logger详解(一)
  9. Android Studio镜像设置
  10. 【android】android短信数据库表