簡體   English   中英

將 session 變量存儲到 mysql

[英]store a session variable into mysql

現在我有這個:

 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? 我一直在嘗試找到一種正確的方法來做到這一點而不會得到一個空值

完整的查詢:

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

這是 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
        }
    });
});

我能夠獲取內容 url 並輸入。 標題仍為空

正如zerkms所說,您可以像存儲任何其他變量一樣存儲 session 變量

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

在你的情況下

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM