duannaozhao4626 2011-07-20 16: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-20 16: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'])."')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部