0

我正在创建一个只有两三个页面的简单网站,并且我正在使用 Froala 编辑器直接从页面编辑内容。所以我有<textarea>一个表单,其 id 为“编辑”(使其成为所见即所得的编辑器)和一个提交按钮。所以基本上我想要它做的是在提交按钮时更新我的​​数据库中的“pages”表(其中type = 1)中的“body”列......这是我的代码:

<?php

    $query = "SELECT * FROM pages WHERE type = 1";
    $result = mysqli_query($dbc, $query);

    $page = mysqli_fetch_assoc($result);

?>

和html:

<form>
    <textarea id="edit" name="body"><?php echo $page["body"]; ?></textarea>
    <button type="submit" class="button button-primary">Save</button>
</form>
4

1 回答 1

0

First add a action to your form and a method.

<form method="post" action="path/to/file-to-update.php">
   <textarea id="edit" name="body"><?php echo $page["body"]; ?></textarea>
   <button type="submit" class="button button-primary">Save</button>
</form>

Add code below to file-to-update.php

$mysqli = new mysqli("localhost", "my_user", "my_password");
$stmt = $mysqli->prepare("UPDATE pages SET body = ? WHERE type = ?");
$stmt->bind_param('si',$_POST[’body’], 1);
$stmt->execute(); 
$stmt->close();

You can read more about mysqli prepare statements here or follow this tutorial

于 2015-03-31T13:26:03.777 回答