waz Posted June 12, 2007 Share Posted June 12, 2007 how am i surpose to set a variable from the previous page check if its same as before if it is then leave the session variable at same value if not change it to $_post['text'] which is the new value to use . but code doesnt seem to work anyone know why. <php session_start(); if($_SESSION['Test'] <> $_POST['textfield']) { echo $_POST['textfield'] && " is not same as the session which is " && $_SESSION['Test']; }else{ $_SESSION['Test'] = $_POST['textfield']; } ?> its really that simple but i cant seem to get it to remeber also its on a php self form thanks waz Link to comment https://forums.phpfreaks.com/topic/55323-solved-session-variable/ Share on other sites More sharing options...
TreeNode Posted June 12, 2007 Share Posted June 12, 2007 Your logic is wrong. If it's not the same, <>, then set the session variable, otherwise it never reaches the $_SESSION['Test'] = $_POST['textfield']; line... unless of course you enter in nothing for the first time vising the site (without the session variable set already). Link to comment https://forums.phpfreaks.com/topic/55323-solved-session-variable/#findComment-273453 Share on other sites More sharing options...
Wuhtzu Posted June 12, 2007 Share Posted June 12, 2007 I don't know what the &&'s are for, but you should use . (dot) to join strings: $_POST['textfield'] . " is not same... " . $_SESSION['Test']; Link to comment https://forums.phpfreaks.com/topic/55323-solved-session-variable/#findComment-273456 Share on other sites More sharing options...
waz Posted June 12, 2007 Author Share Posted June 12, 2007 when it loads there is a default value in the $_POST['textfield'] Link to comment https://forums.phpfreaks.com/topic/55323-solved-session-variable/#findComment-273462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.