简体   繁体   中英

store a session variable into 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

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'])."')");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM