Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign a Session value to a variable 1

Status
Not open for further replies.

WilliamMute007

Programmer
Sep 30, 2007
116
GB
Hi guys,

I've this little dilema. I have been trying for hours now to assign my session value to a variable but no luck. Can anyone please help if possible?

Code:
    <input type="hidden" name="item_name_$i" value=".$_SESSION['name']."/>

Option two

Code:
$restaurant = . $_SESSION['name'];

Both options keep giving me errors. Thanks in advance for your help.
 
What are the errors you're getting? It's impossible to see what exactly you're doing from the short snippets you provided. Please let us know of the errors you're seeing and provide longer examples (is the first code inside an echo or print statement? why are you concatenating the session in the second example?)

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Code:
 $restaurant = . $_SESSION['name'];

what do you expect this to achieve? i.e. what output are you intending? from the information you have provided i suspect that the dot is extraneous.

Code:
 <input type="hidden" name="item_name_$i" value=".$_SESSION['name']."/>

remember all html attributes should be enclosed in double quotes. so the above would look better like this

Code:
echo "<input type=\"hidden\" name=\"item_name_$i\" value=\"$_SESSION[name]\"/>";
or using concatenation, like this

Code:
echo '<input type="hidden" name="item_name_'.$i.'" value="'.$_SESSION['name'].'"/>';

and lastly remember that that session variables are only available once a session has been instantiated. So you MUST call session_start() prior to (i) outputting any data to the browser; and (ii) using $_SESSION
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top