How to Pass Single value from a web page to another using session in php

//Page1.php (from where session value arise)

<?php
   $sn3=$_REQUEST['sn1'];	
	
   session_start();
   $_SESSION['s1']=$sn3;
   $_SESSION['s2']="Codershelpline";
   $_SESSION['s3']=15;
	
   //echo $_SESSION['s1'];
   //echo $_SESSION['s2'];
   //echo $_SESSION['s3'];
?>

<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body>
      <form name="form1" id="form2" method="post" action="">
	 <center>
	   <br><br>				
	   <fieldset style="width: 700px;">
	      <table>						
		 <tr>
		   <td> Serial No </td>
		   <td>   :  </td>
		   <td><input type="text" name="n1" id="n2"></td>							
		 </tr>

		 <tr>
		    <td> Student Name </td>
		    <td>   :  </td>
		    <td><input type="text" name="sn1" id="sn2"></td>							
		  </tr>

		  <tr>
		    <td> Father Name </td>
		    <td>   :  </td>
		    <td><input type="text" name="f1" id="f2"></td>							
		  </tr>

		  <tr>
		     <td></td>
		     <td></td>
		     <td> <input type="Submit" name="sub1" id="sub2" value="Submit">
			  <input type="Submit" name="res1" id="res2" value="Reset">
		     </td>
		  </tr>
	       </table>
	    </fieldset>
	  </center>			
        </form>
      </body>
</html>

//Page2.php (where session value used)

<?php
   session_start();
   $value1=$_SESSION['s1'];
   $value2=$_SESSION['s2'];
   $value3=$_SESSION['s3'];	
   //echo $value1;
   //echo $value2;
   //echo $value3;
?>
<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body>
      <form name="form1" id="form2" method="post" action="">
         <center>
         <br><br>				
            <fieldset style="width: 700px;">
               <table>						
		  <tr>
		     <td> Serial No </td>
		     <td>   :  </td>
		     <td><input type="text" name="n1" id="n2" value="<?php echo $value1;?>"></td>							
		  </tr>
		  <tr>
		     <td> Student Name </td>
		     <td>   :  </td>
		     <td><input type="text" name="sn1" id="sn2" value="<?php echo $value2;?>"></td>							
		  </tr>
		  <tr>
		     <td></td>
		     <td></td>
		     <td> <input type="Submit" name="sub1" id="sub2" value="Submit">
			  <input type="Submit" name="res1" id="res2" value="Reset">
		     </td>
		 </tr>
	      </table>
	   </fieldset>
         </center>			
       </form>
    </body>
</html>

How to Pass Multiple values from a web page to another using Session Array in php

Page1.php

<?php
	error_reporting(E_ERROR | E_PARSE);
	
	$testTxtuname3=$_REQUEST['testTxtuname1'];
	$testPhnumber3=$_REQUEST['testPhnumber1'];
	$testTxtemail3=$_REQUEST['testTxtemail1'];

	session_start();
	$_SESSION['S1']=array(); //Array declaration for session
	
	//Values Assignment in Array Session
	array_push($_SESSION['S1'],$testTxtuname3,$testPhnumber3,$testTxtemail3);
	// OR
	$_SESSION['S1'][0]=$testTxtuname3; 
	$_SESSION['S1'][1]=$testPhnumber3;
	$_SESSION['S1'][2]=$testTxtemail3;
	
	// To Print All Array Session Values, if required	
	foreach($_SESSION['S1'] as $varname)
	{
	   echo $varname;
	}
	
	// To Print customized Array Session Value, if required	
	echo $_SESSION['S1'][0]; 
	echo $_SESSION['S1'][1];
	echo $_SESSION['S1'][2];
?>	
<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body>
      <form name="testpage1" method="post" action="">
	<table>
	   <tr>
	      <td>User Name:-</td>
	      <td><input type="text" name="testTxtuname1" id="testTxtuname2"></td>
	   </tr>
	   <tr>
	      <td>Phone no:-</td>
	      <td><input type="number" name="testPhnumber1" id="testPhnumber2"></td>
	   </tr>
	   <tr>
	      <td>Email:-</td>
	      <td><input type="Email" name="testTxtemail1" id="testTxtemail2"></td>
	   </tr>
	   <tr>
	      <td></td>
	      <td>
		<input type="submit" name="sub1" id="sub2" value="Submit">
		<input type="submit" name="res1" id="res2" value="Reset">
	      </td>
	   </tr>
	</table>
      </form>
    </body>
 </html>

Page2.php

<?php
	error_reporting(E_ERROR | E_PARSE);
	session_start();
	
	$PageTxtuname3=$_SESSION['cart'][0];
	$PagePhnumber3=$_SESSION['cart'][1];
	$PageTxtemail3=$_SESSION['cart'][2];	
?>

<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body>
      <form name="Page1" id="page2" method="post" action="">
	<table>
	   <tr>
	      <td>User Name:-</td>
	      <td><input type="text" name="PageTxtuname1" id="PageTxtuname2" value="<?php 
                  echo $PageTxtuname3;?>"></td>
	   </tr>
	   <tr>
	      <td>Phone no:-</td>
	      <td><input type="number" name="Pagepnumber1" id="Pagepnumber2" value="<?php 
                  echo $PagePhnumber3;?>"></td>
	   </tr>
	   <tr>
	      <td>Email:-</td>
	      <td><input type="Email" name="PageTxtemail1" id="PageTxtemail2" value="<?php 
                  echo $PageTxtemail3;?>"></td>
	   </tr>
	   <tr>
	      <td></td>
	      <td>
		<input type="submit" name="sub1" id="sub2" value="Submit">
		<input type="submit" name="res1" id="res2" value="Reset">
	      </td>
	   </tr>
	</table>
      </form>
    </body>
</html>

 479 total views,  1 views today

Categories: Php

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.