Php 如何将文本保存到数据库tinyMCE
如何将textarea保存到SQL 以下是html:Php 如何将文本保存到数据库tinyMCE,php,html,mysql,tinymce,Php,Html,Mysql,Tinymce,如何将textarea保存到SQL 以下是html: <form method="post" action="text-handler.php"> <textarea name="content" style="width:100%;cursor:text;"></textarea> </form> 而php: <?php session_start(); $user_name = $_SESSION['user_name
<form method="post" action="text-handler.php">
<textarea name="content" style="width:100%;cursor:text;"></textarea>
</form>
而php:
<?php
session_start();
$user_name = $_SESSION['user_name'];
require_once("config/db.php");
require_once("config/db_connection.php");
$newtext = $_POST['content'];
$sql = mysqli_query($db_connection, "INSERT INTO 'texts' ('text', 'user') VALUES ($newtext, $user_name)");
?>
请记住,标识符引号是反勾号而不是单引号:
在您的代码中:
INTO 'texts' ('text', 'user')
^ ^ ^ ^ ^ ^ // use backticks not single quotes
而且这个查询是不安全的,并且直接在语句中注入用户输入,并且容易发生sql注入
最好使用准备好的语句:
session_start();
$user_name = $_SESSION['user_name'];
require_once("config/db.php");
require_once("config/db_connection.php");
$newtext = $_POST['content'];
$sql = 'INSERT INTO `texts` (`text`, `user`) VALUES (?, ?)';
$insert = $db_connection->prepare($sql);
$insert->bind_param('ss', $newtext, $user_name);
$insert->execute();
if($insert->affected_rows > 0) {
echo 'insert complete';
}
我只是在使用这种代码
这是html和////////
/
这是控制部分
公共功能插入项目到数据库($data)
{
}
数据库中的函数,用于将数据发送到数据库
$pdata['description']=$this->input->post('description')
return $this->db->insert('projects', $data);