Here is what is happening:
<?php require_once("./includes/session.php"); ?>
<?php require_once("./includes/db_connection.php"); ?>
<?php require_once("./includes/functions.php"); ?>
<?php include("./includes/layouts/header.php"); ?>
<div class="wrapper">
<?php table_date(); ?>
<div id="current_wk_head" >
<?php current_table(); ?>
</div>
</div>
<div class="wrapper">
<h4 id="directions">Put a check-mark by the days you want to play!</h4>
<form name="input" action="wk1.php" method="post">
<?php week1_changes(); ?>
<div id="submit_section">
<input type="submit" name="playdaz" value="SUBMIT" class="button">
<form name="input" action="wk1.php" method="post">
<input type="submit" name="goback" value="BACK" class="button">
</form>
<p> When you click SUBMIT all days are submitted so, each day should be appropriately checked.</p>
<p> No updates within 24hrs of next play day.</p>
</div>
</div>
<iframe id="forecast_embed" type="text/html" frameborder="0" height="245" src="http://forecast.io/embed/#lat=35.795925&lon=-79.228608&name=Chapel Ridge&color=#6BB9F0&font=Open+Sans"> </iframe>
</div> <!--End container div-->
</body>
</html>
Above is the webpage where the user submits the dates.
if (($today=="Fri") && ($hd_flag=="yes"))
{
//Friday after the cron run
echo "<div id=\"checkboxes\">
<label class=\"tag\"><input type=\"checkbox\" name=\"MON_PRI\" value=\"YES\" class=\"regular-checkbox\"/>MON_PRI</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"MON_ALT\" value=\"YES\" class=\"regular-checkbox\"/>MON_ALT</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"WED\" value=\"YES\" class=\"regular-checkbox\" />WED</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"FRI\" value=\"YES\" class=\"regular-checkbox\" />FRI</label>
</div>";
}
elseif ($today=="Sat")
{
echo "<div id=\"checkboxes\">
<label class=\"tag\"><input type=\"checkbox\" name=\"MON_PRI\" value=\"YES\" class=\"regular-checkbox\"/>MON_PRI</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"MON_ALT\" value=\"YES\" class=\"regular-checkbox\"/>MON_ALT</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"WED\" value=\"YES\" class=\"regular-checkbox\" />WED</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"FRI\" value=\"YES\" class=\"regular-checkbox\" />FRI</label>
</div>";
}
elseif (($today=="Mon") || ($today=="Sun"))
{
echo "<div id=\"checkboxes\">
<label class=\"tag\"><input type=\"checkbox\" name=\"WED\" value=\"YES\" class=\"regular-checkbox\" />WED</label>
<label class=\"tag\"><input type=\"checkbox\" name=\"FRI\" value=\"YES\" class=\"regular-checkbox\" />FRI</label>
</div>";
}
elseif (($today=="Tue") || ($today=="Wed"))
{
echo "<div id=\"checkboxes\">
<label class=\"tag\"><input type=\"checkbox\" name=\"FRI\" value=\"YES\" class=\"regular-checkbox\" />FRI</label>
</div>";
}
if(isset($_POST['playdaz']))
{
$LastName=$_SESSION['LAST_NAME'];
$monpri = (isset($_POST['MON_PRI'])) ? "YES" :"NO";
$monalt = (isset($_POST['MON_ALT'])) ? "YES" :"NO";
$wed = (isset($_POST['WED'])) ? "YES" :"NO";
$fri = (isset($_POST['FRI'])) ? "YES" :"NO";
//Cannot select 2 courses on the same day
if (($monpri =="NO") || ($monalt=="NO"))
{
$LastName=$_SESSION['LAST_NAME'];
if (($today=="Fri") && ($hd_flag=="yes"))
{
//Friday after the cron runs
$query = "UPDATE players SET MON_PRI='$monpri',MON_ALT='$monalt',WED='$wed',FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
elseif ($today=="Sat")
{
$query = "UPDATE players SET MON_PRI='$monpri',MON_ALT='$monalt',WED='$wed',FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
elseif (($today=="Mon")||($today=="Sun"))
{
$query = "UPDATE players SET WED='$wed',FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
elseif (($today=="Tue")||($today=="Wed"))
{
$query = "UPDATE players SET FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
}
}
Above is a section of the function that updates the database
Any help on how to make it so that after the user clicks on the button the table updates to provide feedback the changes have been made?
Cheers!
Very easy to do that.
You can use a header refresh function and it will fix the redirecting property for you. While using it, two basic things must be considered; That it is placed correctly within the page and that the correct parameters are being passed into it, which includes how long we should wait before it finally refreshes to the new location.
Place the header refresh just below the place in your PHP submit code where a logic is being met, or better still before any content is outputted within the php code. It must be placed before any <html>
and <!doctype>
tags.
For your own case, try something like this,
if (($monpri =="NO") || ($monalt=="NO"))
{
$LastName=$_SESSION['LAST_NAME'];
if (($today=="Fri") && ($hd_flag=="yes"))
{
//Friday after the cron runs
$query = "UPDATE players SET MON_PRI='$monpri',MON_ALT='$monalt',WED='$wed',FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
elseif ($today=="Sat")
{
$query = "UPDATE players SET MON_PRI='$monpri',MON_ALT='$monalt',WED='$wed',FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
elseif (($today=="Mon")||($today=="Sun"))
{
$query = "UPDATE players SET WED='$wed',FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
elseif (($today=="Tue")||($today=="Wed"))
{
$query = "UPDATE players SET FRI='$fri' WHERE LAST_NAME='$LastName'";
mysqli_query($connection, $query);
}
header("refresh:3; url=mywebpage.php?action=something&monpri=$monpri");
}
Use the refresh there if that is where you need it.
After this, you try to check the condition if something is set on the your webpage, If it is set, then show Database updated accordingly. Do it like this;
<?php
if(isset($_REQUEST['action']) && $_REQUEST['monpri']="NO") {echo "Database updated accordingly";}?>