0

I have the following example usage:

  $insert = "
  INSERT INTO table (
      field
  ) VALUES (
      '".$_SESSION['field']."'
  )
  ";

For some reason it's inserting blanks and no data is being submitted. Is what I am doing the right way?

I do have multiple fields but they were too many so just shrunk the example to include only one field.

6
  • 8
    Did you call session_start() before the statement? Commented Dec 27, 2011 at 16:12
  • have you initiated the session using session_start() Commented Dec 27, 2011 at 16:13
  • oops my bad. forgot. now after the form is submitted how can i end the session? Commented Dec 27, 2011 at 16:15
  • 2
    You should escape the variable with mysql_real_escape_string() Commented Dec 27, 2011 at 16:17
  • 1
    Well, obviously your variable $_SESSION['field'] does not contain a value that would not be converted into an empty string. Commented Dec 27, 2011 at 16:26

1 Answer 1

1

Use session_start() for starting the session before assigning anything to $_SESSION['field'].

After insertion you can delete session variables but not the session itself using session_unset(), or you can destroy the variables using session_destroy().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.