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
https://forums.phpfreaks.com/topic/141311-session-variable-q/
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
https://forums.phpfreaks.com/topic/141311-session-variable-q/#findComment-739625
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
https://forums.phpfreaks.com/topic/141311-session-variable-q/#findComment-739628
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.