0
我正在编写一个将主题添加到数据库的新网站。将数据从textarea插入到数据库的解决方案
我为内容的标题和textarea做了输入,我用textarea的wysiwyg编辑器为我的文章添加了一些效果。
问题是,当我尝试插入数据到数据库它无法插入textarea的内容,当我删除wysiwyg它完美的作品。
我使用的是PHP,我使用jQuery插入数据而无需刷新页面。
这是我使用的代码===>
ajax.js
$('#share').click(function(){
var title=$("#tilearticle").val();
if(title== ''){$('#tiart').show('slow');}
else{
var datastring= $("#form1").serialize();
var url1='action.php?action=article';
$.post(url1,datastring,function(info){$("#res").html(info);});
}
});
action.php的
if($_GET['action']=='article'){
$get=$_GET['action'];
$title=$_POST['title']; // get data from title input
$content=$_POST['ckeditor1']; // get data from textarea
$image=$_POST['image'];
$date=date("Y/m/d");
$newtitle=string_limit_words($title, 6);
$urltitle=preg_replace('/[^a-z0-9]/i',' ', $newtitle);
$newurltitle=str_replace(" ","-",$newtitle);
$url='/'.$newurltitle.'.html';
$sql=mysql_query("INSERT INTO article (id,title,img,content,url,time) VALUES
('','".$title."','".$image."','".$content."','".$url."','".$date."')") or die(mysql_error());
if($sql){
echo 'work';}else{echo 'nooo';}
}
add.php //添加商品页面
<form class="form-horizontal" action='action.php?action=article' method='post' id='form1' role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">title</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='title' id="tilearticle" placeholder="title">
<span id='tiart'style='color:red;display: none;'><i class='glyphicon glyphicon-info-sign'> </i> pleas fill in the field</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<textarea class="form-control ckeditor" name='ckeditor1' id='textarea' rows="4"> </textarea>
</div>
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" name="image"id="filearticle">
<p class="help-block">Example block-level help text here.</p>
</div> ';
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" name='submit' id='share' class="btn btn-default">Post</button>
</div>
</div>
</form>
逃脱你不执行任何验证,你的代码是vunerable SQL注入,并使用过时的mysql_ *函数。如果你意识到这一点,并且你的代码只是为了学习目的,'addslashes($ date)'可能会解决你的问题。或者更确切地说,因为如上所述,你的代码是不安全的。 – MSadura
@coder你可以给我举例我是新的php –
@MarkS脚本只是为了学习和提高我的技能,我知道风险。我的问题是只是有没有办法删除wysiwyg –