简体   繁体   中英

How I can send value in PHP from one page to another using other than session?

I have multistep form in which on second step i have date input field and next and previous button.I want to fetch values from the database in 3 step by using date input field but i am clicking on next button not submit button.

This is my second step.

  <input type="date" name="date" id="date">
  <input type="button" name="previous" class="previous action-button" value="Previous" />
  <input type="button" name="nextnew" id="nextnew" class="next action-button" value="Next" />

I have used ajax.

 <script>
       $("#nextnew").click(function() {

             var name2 = $("#date").val();
               //alert(name2);

             $.ajax({
             url:"getuser.php",
            type:"GET",
            data:{ id2: name2},
            success:function(data){
            $("#detail").html(data);
               }
              });
        });  
</script>

This is my getuser.php

 <div class="container-fluid" style="margin-top:30px;" id="detail">
 <?php

 include('config.php');
   session_start();  
   if(isset($_REQUEST['id2']))
  {

   $_SESSION['new22']=$_GET['id2'];
   echo "Your Date Selected :-"; echo $_GET['id2'];

   }

 ?>
</div>

I am setting value in session value to fetch value in third step.But my problem is that it will have same value as we set it once and it is fetching the same value always.Is there any way to send value from getuser.php to another page.

我认为您应该在隐藏字段中设置一个值。

The values can be send to multiple pages through url using PHP and JAVASCRIPT.

first.php

Passing first value to next page second.php through url.

<input type="text" id="name">
<input type="button"  value="NEXT" onclick="myFunction()" />


<script>
function myFunction() 
{

var a= document.getElementById('name').value;
location.href ="second.php?var1="+a;

}
</script>

second.php

Now getting the value from first page using PHP $_GET .Then pass this value and second value to third.php through url.

<input type="date" id="name">
<a href="first.php"><input type="button"  value="BACK" /></a>
<input type="button" value="NEXT" onclick="myFunction()" />


<script>
function myFunction() 
{

var a= document.getElementById('name').value;
var b= "<?php $a=$_GET['var1']; echo $a; ?>";
location.href = "third.php?name="+b+"&date="+a;

}
</script>

third.php

<?php

$name=$_GET['name'];
$date=$_GET['date'];
echo  $name;
echo $date;

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM