html - PHP Session variable is not saving -


i've looked through problems session variable not saving , don't see problem i'm going ask it.

i have form once submitted searches database name. initial form on page 1. on page 2 take the variable page 1 , save this

    $searchterm = $_post['find']; 

which used search database , works perfectly. under have sql statement have placed this

    //initialize session     if (!isset($_session)) {       session_start();     }     $_session['searchterm'] = $searchterm; 

i have tested $_session['searchterm'] on page 2 make sure saving properly, , does. issue comes in when try go 3rd page confirm page form page 2. have session start clause @ top of 3rd page , inserted

ini_set('display_errors',1);  error_reporting(e_all);  

to check errors, no errors displayed. next step test session see if refreshing session id. found script on site www.webassist.com/forums/posts.php?id=5735 test whether server possibly causing issue. script works fine no problems, showing server not problem. when upload 2nd , 3rd page server , put in

    <?php echo session_id(); ?> 

the numbers page 2 , page 3 different therefore making variable null. did further research , thought might because there session_destroy or session_unset didn't put 1 of these on either page. when tried on local machine got same session id still session variable set blank.

does have other ideas on how or why happen?

**********edit *********************

page 1 has form

                <form name="search" method="post" action="page2.php">                     <div>                     <!-- search-->                     <label>search last name:</label>                         <div>                             <table width="100%">                                 <tr>                                     <td><input type="text" id="" name="find" placeholder=""></td>                                     <td><button id="submit" type="submit"><span>search</span></button></td>                                 </tr>                             </table>                         </div>                     </div>                 </form>  

page 2

    $searchterm = $_post['find'];       if(!empty($searchterm ) && ctype_alpha($searchterm ))     {     $whereclause = "where mytable.lastname = '".$searchterm ."'";     }     else {     $whereclause = "";     }      // sql query here 1 searches long , used $whereclause above.      // second sql query submitted if button form below hit here.      $insertgoto = "confirmpage3.php";       if (isset($_server['query_string'])) {         $insertgoto .= (strpos($insertgoto, '?')) ? "&" : "?";         $insertgoto .= $_server['query_string'] ;        }       header(sprintf("location: %s", $insertgoto));      //initialize session     if (session_id() == '') {       session_start();     }     $_session['searchterm'] = $searchterm;       // form listed below rest of html  

page 3

    <?php if(session_id() == '') session_start(); ?>       if(!empty($_session['searchterm']) && ctype_alpha($_session['searchterm']))     {     $whereclause = "where mytable.lastname = '".$_session['searchterm'] ."'";     }     else {     $whereclause = "";     }      // more sql statement here 1 selecting not updating or changing anything.      // table below used hold items retrieved database. 

***********edit 2 , fix**********

so after , few of you, aaron gong suggested start blank page , go there. did , have diagnosed issue. hadn't thought of should have. don't using dreamweaver , remember why. when created page 2 used dreamweavers insert code insert sql statement updating. placed in code these lines of code.

    $editformaction = $_server['php_self'];     if (isset($_server['query_string'])) {       $editformaction .= "?" . htmlentities($_server['query_string']);     } 

this mess if trying send user page confirm entries. commented out , set $editformaction page , used in header string , viola fixed issue. hadn't realized when refreshing page emptying $_post variable , found error through empty pages suggest aaron.

hope helps else , never trust code dreamweaver again. learned code hand , should know better in hurry , thought oh won't harm it.

thanks again suggestions.

not sure 3rd page looks mine be:

session_start(); // use session variable on page. function must put on top of page.  if( isset($_session['i_am_in']) ) echo "logged in"; 

my page 2:

if ($login_ok) {     session_start(); // create session & settings     $_session['abc123'] = 'whatever';     header('location: page3.php'); } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -