Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:54:01+00:00 2026-06-14T22:54:01+00:00

I have an application where the user displays their assessment name, date and time

  • 0

I have an application where the user displays their assessment name, date and time in the relevant text inputs. Now what happens is that when the user submits the form, it displays a confirmation.

Below is the code (editsessionadmin.php):

 <script>
    function showConfirm(){

    var examInput = document.getElementById('newAssessment').value;
    var dateInput = document.getElementById('newDate').value;
    var timeInput = document.getElementById('newTime').value;

    var confirmMsg=confirm("Are you sure you want to update the following:" + "\n" + "Exam: " + examInput +  "\n" + "Date: " + dateInput + "\n" + "Time: " + timeInput);

    }


    </script>   

    <?php

    $sessionquery = "
    SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
    FROM Session
    WHERE
    (ModuleId = ?)
    ORDER BY SessionName 
    ";

    $sessionqrystmt=$mysqli->prepare($sessionquery);
    // You only need to call bind_param once
    $sessionqrystmt->bind_param("s",$moduleId);
    // get result and assign variables (prefix with db)

    $sessionqrystmt->execute(); 

    $sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);

    $sessionqrystmt->store_result();

    $sessionnum = $sessionqrystmt->num_rows();   

    if($sessionnum ==0){
    echo "<p>Sorry, You have No Assessments under this Module</p>";
    } else { 

    $sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
    $sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

    while ( $sessionqrystmt->fetch() ) {
       if(time() > strtotime($dbSessionDate." ".$dbSessionTime)){
             $class = 'red';
        } else {
             $class = 'green';
        }
    $sessionHTML .= sprintf("<option value='%s' style='color: %s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;  
    }


    $sessionHTML .= '</select>';


    $assessmentform = "<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'>
    <p><strong>Assessments:</strong> {$sessionHTML} </p>   
    </form>";

    echo $assessmentform;

    }



    $editsession = "<form action=".htmlentities($_SERVER['PHP_SELF'])." method='post' id='updateForm'>

        <p><strong>New Assessment's Date/Start Time:</strong></p>
        <table>
        <tr>
        <th>Assessment:</th>
        <td><input type='text' id='newAssessment' name='Assessmentnew' readonly='readonly' value='' /> </td>
        </tr>
        <tr>
        <th>Date:</th> 
        <td><input type='text' id='newDate' name='Datenew' readonly='readonly' value='' /> </td>
        </tr>
        <tr>
        <th>Start Time:</th> 
        <td><input type='text' id='newTime' name='Timenew' readonly='readonly' value=''/><span class='timepicker_button_trigger'><img src='Images/clock.gif' alt='Choose Time' /></span> </td>
        </tr>
        </table>
        <div id='datetimeAlert'></div>

        <p><input id='updateSubmit' type='submit' value='Update Date/Start Time' name='updateSubmit' onClick='myClickHandler(); return false;'/></p>

        </form>
    ";

    echo $editsession;


    }

    ?>

    <script type="text/javascript">

    function myClickHandler(){ 
         if(editvalidation()){ 
                    showConfirm(); 
         } 
    }

    </script>

Now I want to run an UPDATE command to update the exam’s date and time in the database after the user has confirmed the confirmation and compile a SELECT query so that if the update happened, then echo it was a success, else echo there was an error.

My question is first of all is the code below correct and second of all where do I place this code so that it runs the commands after the confirmation has been confirmed?

 <?php

    $sessionname = (isset($_POST['Assessmentnew'])) ? $_POST['Assessmentnew'] : ''; 
    $sessiondate = (isset($_POST['Datenew'])) ? $_POST['Datenew'] : ''; 
    $sessiontime = (isset($_POST['Timenew'])) ? $_POST['Timenew'] : ''; 

        $updatesql = "UPDATE Session SET SessionDate = ?, SessionTime = ? WHERE SessionName = ?";                                           
        $update = $mysqli->prepare($updatesql);
        $update->bind_param("sss", $sessiondate, $sessiontime, $sessionname);
        $update->execute();

       $query = "SELECT SessionName, SessionDate, SessionTime FROM Session WHERE SessionName = ?";
       // prepare query
       $stmt=$mysqli->prepare($query);
       // You only need to call bind_param once
       $stmt->bind_param("sss", $sessionname, $sessiondate, $sessiontime);
       // execute query
       $stmt->execute(); 
       // get result and assign variables (prefix with db)
       $stmt->bind_result($dbSessionName, $dbSessionDate, $dbSessionTime);
       //get number of rows
       $stmt->store_result();
       $numrows = $stmt->num_rows();

       if ($numrows == 1){

           echo "<span style='color: green'>Your Assessment's new Date and Time have been updated</span>";

       }else{

           echo "<span style='color: red'>An error has occurred, your Assessment's new Date and Time have not been updated</span>";
    ?>

UPDATE:

Below is code for editsessionadmin.php

<script>
function showConfirm(){

var examInput = document.getElementById('newAssessment').value;
var dateInput = document.getElementById('newDate').value;
var timeInput = document.getElementById('newTime').value;

var confirmMsg=confirm("Are you sure you want to update the following:" + "\n" + "Exam: " + examInput +  "\n" + "Date: " + dateInput + "\n" + "Time: " + timeInput);

if (confirmMsg==true)
{
submitform();   
}
}

function submitform()
{

$.post("updatedatetime.php", $("#updateForm").serialize() ,function(data){
var updateFormO = document.getElementById("updateForm");
updateFormO.submit();
}); 

}
</script>   

<?php
    $sessionquery = "
        SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
        FROM Session
        WHERE
        (ModuleId = ?)
        ORDER BY SessionName 
        ";

        $sessionqrystmt=$mysqli->prepare($sessionquery);
        // You only need to call bind_param once
        $sessionqrystmt->bind_param("s",$moduleId);
        // get result and assign variables (prefix with db)

        $sessionqrystmt->execute(); 

        $sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);

        $sessionqrystmt->store_result();

        $sessionnum = $sessionqrystmt->num_rows();   

        if($sessionnum ==0){
        echo "<p>Sorry, You have No Assessments under this Module</p>";
        } else { 

        $sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
        $sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

        while ( $sessionqrystmt->fetch() ) {
           if(time() > strtotime($dbSessionDate." ".$dbSessionTime)){
                 $class = 'red';
            } else {
                 $class = 'green';
            }
        $sessionHTML .= sprintf("<option value='%s' style='color: %s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;  
        }

        $sessionHTML .= '</select>';

        $assessmentform = "<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'>
        <p><strong>Assessments:</strong> {$sessionHTML} </p>   
        </form>";

        echo $assessmentform;

        }



        $editsession = "<form action=".htmlentities($_SERVER['PHP_SELF'])." method='post' id='updateForm'>

            <p><strong>New Assessment's Date/Start Time:</strong></p>
            <table>
            <tr>
            <th>Assessment:</th>
            <td><input type='text' id='newAssessment' name='Assessmentnew' readonly='readonly' value='' /> </td>
            </tr>
            <tr>
            <th>Date:</th> 
            <td><input type='text' id='newDate' name='Datenew' readonly='readonly' value='' /> </td>
            </tr>
            <tr>
            <th>Start Time:</th> 
            <td><input type='text' id='newTime' name='Timenew' readonly='readonly' value=''/><span class='timepicker_button_trigger'><img src='Images/clock.gif' alt='Choose Time' /></span> </td>
            </tr>
            </table>
            <div id='datetimeAlert'></div>

            <p><input id='updateSubmit' type='submit' value='Update Date/Start Time' name='updateSubmit' onClick='myClickHandler(); return false;'/></p>

            </form>
        ";

        echo $editsession;


        }

        ?>

        <script type="text/javascript">

        function myClickHandler(){ 
             if(editvalidation()){ 
                        showConfirm(); 
             } 
        }

        </script>

In the above code I added a jquery/ajax function submitform() where after the confirmation it will perform a post in the background to the updatedatetime.php page. There is where it displays the update and select statments. Problem is that it is not doing the update or displaying the echo in the editsessionadmin.php page

Below is code for updatedatetime.php:

    <?php

 // connect to the database
 include('connect.php');

  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
  }

    $sessionname = (isset($_POST['Assessmentnew'])) ? $_POST['Assessmentnew'] : ''; 
    $sessiondate = (isset($_POST['Datenew'])) ? $_POST['Datenew'] : ''; 
    $sessiontime = (isset($_POST['Timenew'])) ? $_POST['Timenew'] : ''; 

    $updatesql = "UPDATE Session SET SessionDate = ?, SessionTime = ? WHERE SessionName = ?";                                           
    $update = $mysqli->prepare($updatesql);
    $update->bind_param("sss", $sessiondate, $sessiontime, $sessionname);
    $update->execute();

    $query = "SELECT SessionName, SessionDate, SessionTime FROM Session WHERE SessionName = ?";
    // prepare query
    $stmt=$mysqli->prepare($query);
    // You only need to call bind_param once
    $stmt->bind_param("sss", $sessionname, $sessiondate, $sessiontime);
    // execute query
    $stmt->execute(); 
    // get result and assign variables (prefix with db)
    $stmt->bind_result($dbSessionName, $dbSessionDate, $dbSessionTime);
    //get number of rows
    $stmt->store_result();
    $numrows = $stmt->num_rows();

    if ($numrows == 1){

    echo "<span style='color: green'>Your Assessment's new Date and Time have been updated</span>";

    }else{

    echo "<span style='color: red'>An error has occured, your Assessment's new Date and Time have not been updated</span>";



            ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:54:02+00:00Added an answer on June 14, 2026 at 10:54 pm

    PHP runs on the server, the user giving the confirmation is on the client. That means you have to use javascript/Jquery to trigger an event when the user gives his confirmation, then call a php that does the UPDATES or other query. This can be done with a AJAX call, or just submiting a form or with a url redirection.

    So it should be like this:

    1. First A.php that gets the form submited with the user data, does some queries and displays the confirmation text. This also has javascript code to submit the confirmation to another B.php, normally this would be done with a AJAX call that will receive something in return.
    2. Second B.php that receives the confirmation of the first A.php, does the UPDATES and returns something to tell the first A.php all the query went OK. If something goes wrong it could return a error code, or a error message detailing the error.
    3. A.php shows the return of B.php to the user.

    UPDATED CODE:

    $.post("updatedatetime.php", $("#updateForm").serialize() ,function(data){
        alert(data);
    }); 
    

    The function(data) at the end is a callback function, that means that it will be executed once updatedatetime.php ends its execution. The variable data it receives is the return of updatedatetime.php (what you echo in that php)

    To check if your AJAX is executing properly, if the variables have values, the return, etc. I would recommend to use Firebug, in its console it will display all this info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application (editsessionadmin.php) where the user displays their assessment's name, date and
I have an application that displays a dialog when the user needs to enter
In another application I have retrieved and stored a user's data, including their date
We have a customer that would like to modify application user messages that we
I have an application that allows the user to take a picture with the
I have an ASP.NET web forms application that requires that requires that a user
In my Webforms 3.5 application, I have a GridView of users that displays the
I have an application that pulls information from a web server and displays it.
I have an application [here][1] where an user is able to select their options
I have a web application (.NET 2.0 coded in C#) that displays pages both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.