使用tiny mce作为富文本编辑器。尝试将代码示例添加为博客文章时出现错误。网站使用php-mysql
我正在使用tinymce作为文本区域。将内容添加到数据库的php代码如下:
mysql_select_db('rough_site');
if(($_POST['post_content'] != ''))
{
$current_date= date("Y-m-d");
//$content_of_post = stripslashes($_POST['post_content']);
$content_of_post=$_POST['post_content'];
//$post_title=$_POST['post_title'];
if(($_POST['post_title']) =='')
{
$post_title="Untitled".time();
}
$addpost = "INSERT into posts (user_name, post_title , post_content,post_total,post_date)
VALUES ( '$_SESSION[user_name]' , '$post_title' , '$content_of_post', 0 , '$current_date') " ;
if(!$confirmpost)
{
echo "Problem adding your post . Please resubmit it . " ."<br/>" . mysql_error();
}
现在,如果我尝试添加一些php代码作为示例,它会给我这样的错误:
添加您的帖子时出现问题。请重新提交。 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在“/em>”附近使用的正确语法); 打印$密码。 “是mypassword的加密版本&”在第 2 行。
这里出了什么问题?谢谢!
我想添加的示例代码:
<?php
$password = crypt('mypassword');
print $password . “ is the encrypted version of mypassword”;
?>
<?php
$password = crypt('mypassword' , 'd4');
print $password . " is the CRYPT_STD_DES version of mypassword<br>";
$password = crypt('mypassword' , 'k783d.y1g');
print $password . " is the CRYPT_EXT_DES version of mypassword<br>";
$password = crypt('mypassword' , '$1$d4juhy6d$');
print $password . " is the CRYPT_MD5 version of mypassword<br>";
$password = crypt('mypassword' , '$2a$07$kiuhgfslerd...........$');
print $password . " is the CRYPT_BLOWFISH version of mypassword<br>";
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在从表单收到的输入上使用
mysql_real_escape_string
:此外,如果您有
$_POST['post_title']
,则不会设置您的$post_title
代码>设置。这也会导致 SQL 错误。应该是这样的:另外,直接将输入数据附加到 sql 查询中是一种非常糟糕的做法。考虑使用 mysqli 和 准备好的语句
You should use
mysql_real_escape_string
on the input you receive from form:Also, your
$post_title
is not being set if you have$_POST['post_title']
set. This will also end up in an SQL error. Should be something like:Also, appending input data into sql query directly is a very bad practice. Consider using mysqli and prepared statemnts
我猜您需要在发布到数据库之前转义您的输入。看来您的查询在第一个“引用”处中断,这是有道理的。
由于您使用的是旧版 mysql 扩展,请查看 此页面 因此,
在分配 $addpost 变量之前,您应该执行类似的操作:
顺便说一句,您应该对所有字段执行此操作,以降低 mySQL 注入攻击的风险。希望我的猜测是正确的,这会有所帮助。
I'm guessing that you need to escape your input before posting to the database. It looks like your query breaks at the first 'quote' which makes sense.
Since you're using the legacy mysql extension have a look at this page on the manual
So you would do something like this before assigning your $addpost variable:
You should do that for all fields, by the way, to reduce the risk of mySQL injection attacks. Hope I'm right in guessing and that this helps.