0

Hi,

I have want to insert session variable in my database. I have developed a blog and I want to insert session variable in one of the fields defined in my database. I have the code which can insert other fields in the database but I do not know how to insert the session variable.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO blog (title, specialization, message, time, email) VALUES (%s, %s, %s, %s , %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['specialization'], "text"),
                       GetSQLValueString($_POST['words'], "text"));

In the table I have the following fields:

blog_id, title, message, time, email.

Email in the last will be taken from the session variable. Can any one please help me and tell me the code which can take an email from session and put it in the database.

Regards,

Bilal A. Khan

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by BilalAKhan
0

Try :

session_start();
if (isset($_SESSION['session_email']))
{
echo $_SESSION['session_email'];
// You can use $_SESSION['session_email'] to insert the email wherever you want just like a simple variable
}
0

Try :

session_start();
if (isset($_SESSION['session_email']))
{
echo $_SESSION['session_email'];
// You can use $_SESSION['session_email'] to insert the email wherever you want just like a simple variable
}

Thank you very much for the reply. I have changed my syntax something like this:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO blog (title, specialization, message, email) VALUES (%s, %s, %s ,".$_SESSION['MM_Username'].")",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['specialization'], "text"),
                       GetSQLValueString($_POST['words'], "text"));

With this code it is giving me the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com)' at line 1

Can anyone please tell me what does this error mean? I believe it has to do something with the way I am inserting the session variable in my database because my session variable contains an email address as login.

Any help will be highly appreciated.

Regards,

Bilal A. Khan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.