Since days I have tried to solve a problem but it hasn't still succeeded so far.
The solution would be that I choose a number from 0 till 5 from a SELECT and in this case input fields appear depending on the numbers, e.g. if I choose 3 from the SELECT, 3 input fields can be seen.
After that I would like to store data in these input fields. The actual solution that with Ajax I transfer the data to PHP, which stores the given value in a session cookie. The problems begin from here.
I would like to implement if a user arrives my webpage stores some activities from the visitors which are used later if they visit the page again. The basic thought is that I use SESSION during their visiting time until they don't delete the cookies.
Once I did that PHP create the session and it is stored but if I reload the site, the session is lost.
Actually I would like to implement: - store the SELECT value in a SESSION till deleting it, so repeat visitor can be identified. - also store the input fields in a SESSION - if a guest visits the site again and e.g. the SELECT is 4, then in the SELECT number 4 be chosen and further 4 input fields appear with the stored values.
I don't think the PHP is the best solution... Could you help me?
Thanks for your all helps in advance.
Best Regards, Atti
<?php
session_start();
echo $_SESSION['gyk1'];
?>
<p id="gyszam"></p>
<div class="row">
Type
<select name="type" id="type">
<option name="gy0" value="0">0</option>
<option name="gy1" value="1">1</option>
</select>
</div>
<div class="row" id="gyk1">
<?php
if (isset($_SESSION['gyk1'])) {
$session_gyk1 = $_SESSION['gyk1'];
echo "<input type='number' id='gy1' class='gykk1' name='gyn1' min='0' max='17' value='$session_gyk1' ><br>";
} else {
echo "<input type='number' id='gy1' class='gykk1' name='gyn1' min='0' max='17' /><br>";
}
?>
</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function() {
$('#gyk1').hide();
$('#type').change(function(){
if($('#type').val() == '1') {
$('#gyk1').show();
} else {
$('#gyk1').hide();
}
});
});
$(function() {
$("input#gy1.gykk1").change(function(){
var gykk1 = $(this).val();
$.ajax({
type: "POST",
url: "php.php",
data: {gyk1: gykk1},
success: function(records){
$("#gyszam").html((records));
}
});
});
});
</script>
PHP file:
<?php
session_start();
$gyk1 = $_POST['gyk1'];
$_SESSION['gyk1'] = $gyk1;
?>