dongxuan1660 2014-09-07 10:58 采纳率: 100%
浏览 85
已采纳

处理单引号和双引号php和ajax

hello all i am having a project where a user can write any comment on any post currently everything is going very good i mean that the user can post and comment successfully but when the user comments any line which contains any single or double quote the whole text is just skipped nothing is displayed . like the text i'll call you is not displayed but i will call you is displayed i know i need to use addslashes but i don't know how to use it. i tried to addslashe after the post variable and then send it to database bit nothing happens

here is my form and code

JS

function formsubmitionbyajax(obj){
        $.ajax({ type: 'post',
        url: 'home_formhandler1.php',
        data: $("#postform").serialize(),
        success: function(){
        $("#LOADreftraed").load("Mypage.php #LOADreftraed");
        $("#postform")[0].reset();
}   } );    return false;   }

PHP action page

 $views=$_POST['views'];
 $comment=$_POST['comment'];
 $onid=$_POST['onid'];
 $onemail=$_POST['onemail'];

  $insertposts=mysql_query("insert into `fk_views` (`views`,`session_id`,`email`,`Date`) 
  values    ('$views','$sid','$email','$time')");
   exit;

i have many forms like this and is there any way to addslash to all the post variables and then send them to BD please help me .

  • 写回答

1条回答 默认 最新

  • dongluan2612 2014-09-07 11:13
    关注

    use it like

    $views=mysql_real_escape_string($_POST['views']);
    

    for more see documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog