duannaozhao4626 2011-07-21 00:51
浏览 40
已采纳

将会话变量存储到mysql中

Right now I have this:

 session_start()
$_SESSION['title'] = $_POST['title'];

I store a variable from jquery to be preserved in the php session, my question now is ...using mysql_query()...how would I store the SESSION variable in the database? I've been trying to find out a proper way to do this without getting an empty value

the full query:

mysql_query("INSERT INTO titles (content, type, url, title) 
VALUES ('$content','7',$url',".mysql_real_escape_string($_SESSION['title'])."')");

here is the jquery :

var title = $(".hidden").text();            
 $.post("tosqltwo.php", { title: title} );              
 var url = $(".hide").text();       

                $(".button").click(function() {
    var content = $(this).siblings().outerHTML();
    $.ajax({
        type: "POST",
        url: "tosqltwo.php",
        data: {
            content: content, url: url
        }
    });
});

I am able to get the content, url and type. The title remains empty

  • 写回答

1条回答 默认 最新

  • douya1061 2011-07-21 00:53
    关注

    You can store session variable like any other variable, as zerkms said

    mysql_query("INSERT INTO titles (title) VALUES ('".mysql_real_escape_string($_SESSION['title'])."')");
    

    in your case

      mysql_query("INSERT INTO titles (content, type, url, title) VALUES ('".mysql_real_escape_string($content)."','7','".mysql_real_escape_string($url)','".mysql_real_escape_string($_SESSION['title'])."')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧