I'm trying to create a php page where I can cycle through a database table line-by-line. I have created a page that allows me to do this but I can't seem to be able to combine the forms so that clicking the button to go to the next/previous form also submits the data entry form.
I've made a very simplified version of the code that does not have a database attached to show you what I've been doing:
<?php
session_start();
// Create an array to cycle through
$a = array('1', '2', '3', '4');
if(isset($_POST['village']))
{
$_SESSION['counter']++;
}
elseif(isset($_POST['village1']))
{
$_SESSION['counter'] = $_SESSION['counter']-1;
}
elseif(isset($_POST['testVar']))
{
$_SESSION['testVar'] = $_POST['testVar'];
}
else
{
$_SESSION['counter'] = 0;
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content Type" charset="utf-8"/>
<title>TEST</title>
</head>
<body>
<!-- Previous value form -->
<form name="prevValue_form" method="post" action="" enctype="multipart/form-data">
<div style="float: left">
<button class="btn btn-success" name="prev" id="prev" value="prev" style="font-size: 20px;"><</a>
</div>
<input type="text" name="village1" value="testing" />
</form>
<!-- Next value form -->
<form name="nextValue_form" method="post" action="" enctype="multipart/form-data">
<div style="float: left">
<button class="btn btn-primary" name="next" id="next" value="next" style="font-size: 20px;">></button>
</div>
<input type="text" name="village" value="testing" />
</form>
<!-- data input section -->
<div id="main" accept-charset="UTF-8" class="form">
<form name="dataEntry_form" method="post" action="" enctype="multipart/form-data">
<!-- data input variable -->
tester: <input name="testVar" value="" />
<!-- Values to display if code is working -->
<br clear="all" /><br />
count: <?php echo $a[$_SESSION['counter']]; ?>
<br clear="all" />
test variable: <?php echo $_SESSION['testVar']; ?>
<!-- submit the data entry form -->
<p><input name="submit" type="submit" value="Submit" /></p>
</form>
</div>
</body>
</html>
<script>
$("#nextValue_form button").click(function (ev) {
ev.preventDefault()
if ($(this).attr("value") == "next") {
$("#test_form").submit();
$("#test_form2").submit();
}
});
$("#prevValue_form button").click(function (ev) {
ev.preventDefault()
if ($(this).attr("value") == "prev") {
$("#test_form").submit();
$("#test_form1").submit();
}
});
</script>
Like I said above, the page works. However, I'm moving some people over from a bunch of Access databases to SQL Server and they don't like that the inputs don't automatically submit when they click the button to go to the next record. I'd imagine this is possible to accomplish, but I'm more of a database person than a PHP person and I've been having trouble with it.
Thanks for any help