1

I have to save form value into PHP session and want to keep save all form value until form submit:

I have trying like this:

$pattern = '';
if(isset($_REQUEST['submit'])) :
   $s1 =  $_REQUEST['step1'];
   $s2 = $_REQUEST['step2'];
   $s3 = $_REQUEST['step3'];
   $s4 = $_REQUEST['step4'];
$pattern .= $s1.$s2.$s3;
$p_cat= $_REQUEST['p_cat'];

$_SESSION['mywine'] =  $pattern;
$_SESSION['quantity'] =  $_REQUEST['step4'];

if($p_cat == 'mixed')
$p_cat = 'red,white';
else $p_cat=  $_REQUEST['p_cat'];
endif;



 $my_wine = $_SESSION['mywine'];
 $qun = $_SESSION['quantity'];

         $args = array(
             'post_type' => 'product',
                 'product_cat' => $p_cat,
                   'posts_per_page' => 3,
                           'meta_query' => array(
                              array(
                               'key' => 'product_score_pattern',
                                'value' => $my_wine,
                                'compare' => '='
                                )
                               )
                             );

        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {

            while ( $loop->have_posts() ) : $loop->the_post(); 

                 endwhile;
                endif;

This code able to save data into session but when I will refresh page then session value will be empty.

I want to keep form vale until form submit. How this will be possible?

1 Answers1

0

You have to call session_start() before to assign or access $_SESSION variable like below.

session_start();
if(isset($_REQUEST['submit'])) :
 $_SESSION['sessionvalue'] = $_REQUEST['username'];
endif;
echo $_SESSION['sessionvalue'];

Okay, you are using wordpress, it is not allowing create session.. you need to refer this

https://wordpress.org/support/topic/sessions-not-working-tried-everything

Wordpress session management

Community
  • 1
  • 1
Disha V.
  • 1,834
  • 1
  • 13
  • 21
  • I have already added session_start() and it will save value into session but I want to keep save this value until next submit –  Sep 09 '15 at 09:53