Jump to content

session variable Q


dadamssg

Recommended Posts

i want to keep what a user inputs in my form in a session variable so i can transfer it over to a page where he can then check what he inputs before submitting to my database. how do i store the POST variables into a session variable to use in the next page?

this isn't working

 

$_SESSION['$_POST['$title']]= $title;

 

the name for the input field is 'title'

Link to comment
Share on other sites

$_SESSION['$_POST['$title']]= $title;

 

ok.. idk you obviously don't see whats wrong with this picture, however I'll risk losing first post in order to FULLY explain it to you lol

 

ofcourse you'd use the superglobal $_SESSION

 

but

 

you started a single quote which would denote a literal text value would follow, then terminated by another single quote..

 

E.G.

 

$_SESSION['literalTextValue']

 

however you are doing 2 things wrong here

 

literal strings do not evaluate variables for starters

 

secondly you forgot a terminating quote (')

 

My advice for you here, is to always when you're expecting to write a string, automatically write two quotes, instead of just 1 before, and 1 after.. this way you can never make this mistake again.

 

for the variable, you need to know that that will never work

 

and would probably not be the best option for you!

 

plain and simple

 

$_SESSION['title'] = $_POST['title'];

 

would do just fine..

 

please don't just copy/paste the aboev.. try and know exactly why your script wasn't working, and never make the mistake again..

 

Happy Coding

 

- Russell

Link to comment
Share on other sites

i think thats it but why am i getting another error when im trying to call that variable later? any ideas?

 

<?php

/* File: checkpost.php*/

include("caneck.inc");

session_start();

$_SESSION['title'] = $_POST['title'];
$_SESSION['description'] = $_POST['description'];
$_SESSION['event'] = $_POST['event'];



echo "<table border='7'>
       <tr>
       <td><b>Title:&nbsp</b></td><td>$_SESSION['title']</td>
       </tr>                        
       <tr>
       <td><b>Description:&nbsp</b></td><td>$_SESSION['description']</td>
       </tr>
       <tr>
       <td><b>Event Type:&nbsp</b></td><td>$_SESSION['event']</td>
       </tr>
       <tr>
       <td colspan=2><center><form action='submitpost.php' method='POST'><input type='submit' name='post' value='post'>
       </center></form>
       </td>                       
       </tr>
       </table>";
  
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.