Note that there are some explanatory texts on larger screens.

plurals
  1. POsuccess/error message keeps disappearing while submitting form
    primarykey
    data
    text
    <p>I have an application <code>(editsessionadmin.php)</code> where the user displays their assessment's name, date and time in the relevant text inputs. Now when the user submits, it will display a confirmation, when the user confirms, then by using ajax, it navigates to the <code>updatedatetime.php</code> where it will update the assessment's time and date in the database and display the success or error message at the top of the <code>editsessionadmin.php</code> page.</p> <p>But I have a small problems.</p> <p>Problem : Using a div tag, I am able to retrieve the error or success message after the update from the <code>updatedatetime.php</code> script and display it in the <code>editsessionadmin.php</code> script by using this jquery code <code>$("#targetdiv").html(data)</code>. Problem is though is that when the user submits the form, it displays the message and then the message disappears after form is submitted. I want the message to be displayed at the top of the <code>editsessionadmin.php</code> page and not disappear. Why is it disappearing?</p> <p>Below is the code for editsessionadmin.php</p> <pre><code> &lt;script&gt; function submitform() { $.ajax({ type: "POST", url: "/updatedatetime.php", data: $('#updateForm').serialize(), success: function(html){ $("#targetdiv").html(html); } }); } function showConfirm(){ var examInput = document.getElementById('newAssessment').value; var dateInput = document.getElementById('newDate').value; var timeInput = document.getElementById('newTime').value; if (editvalidation()) { 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(); } } } $('body').on('click', '#updateSubmit', showConfirm); &lt;/script&gt; &lt;h1&gt;EDIT AN ASSESSMENT'S DATE/START TIME&lt;/h1&gt; &lt;p&gt;You can edit assessment's Date and Start time on this page. Only active assessments can be editted.&lt;/p&gt; &lt;div id="targetdiv"&gt;&lt;/div&gt; &lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post" onsubmit="return validation();"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Course: INFO101&lt;/th&gt; &lt;th&gt;Module: CHI2513&lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt;&lt;input id="moduleSubmit" type="submit" value="Submit Course and Module" name="moduleSubmit" /&gt;&lt;/p&gt; &lt;/form&gt; .... &lt;?php $editsession = "&lt;form id='updateForm'&gt; &lt;p&gt;&lt;strong&gt;New Assessment's Date/Start Time:&lt;/strong&gt;&lt;/p&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Assessment:&lt;/th&gt; &lt;td&gt;&lt;input type='text' id='newAssessment' name='Assessmentnew' readonly='readonly' value='' /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;Date:&lt;/th&gt; &lt;td&gt;&lt;input type='text' id='newDate' name='Datenew' readonly='readonly' value='' /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;Start Time:&lt;/th&gt; &lt;td&gt;&lt;input type='text' id='newTime' name='Timenew' readonly='readonly' value=''/&gt;&lt;span class='timepicker_button_trigger'&gt;&lt;img src='Images/clock.gif' alt='Choose Time' /&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div id='datetimeAlert'&gt;&lt;/div&gt; &lt;button id='updateSubmit'&gt;Update Date/Start Time&lt;/button&gt; &lt;/form&gt; "; echo $editsession; } ?&gt; </code></pre> <p>Below is the code for updatedatetime.php:</p> <pre><code>&lt;?php // connect to the database include('connect.php'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); die(); } echo 'sumbit successful'; $sessionname = (isset($_POST['Assessmentnew'])) ? $_POST['Assessmentnew'] : ''; $sessiondate = (isset($_POST['Datenew'])) ? $_POST['Datenew'] : ''; $sessiontime = (isset($_POST['Timenew'])) ? $_POST['Timenew'] : ''; $formatdate = date("Y-m-d",strtotime($sessiondate)); $formattime = date("H:i:s",strtotime($sessiontime)); $updatesql = "UPDATE Session SET SessionDate = ?, SessionTime = ? WHERE SessionName = ?"; $update = $mysqli-&gt;prepare($updatesql); $update-&gt;bind_param("sss", $formatdate, $formattime, $sessionname); $update-&gt;execute(); echo 'update successful'; $query = "SELECT SessionName, SessionDate, SessionTime FROM Session WHERE SessionName = ?"; // prepare query $stmt=$mysqli-&gt;prepare($query); // You only need to call bind_param once $stmt-&gt;bind_param("s", $sessionname); // execute query $stmt-&gt;execute(); // get result and assign variables (prefix with db) $stmt-&gt;bind_result($dbSessionName, $dbSessionDate, $dbSessionTime); //get number of rows $stmt-&gt;store_result(); $numrows = $stmt-&gt;num_rows(); echo 'select successful'; if ($numrows == 1){ echo "&lt;span style='color: green'&gt;Your Assessment's new Date and Time have been updated&lt;/span&gt;"; }else{ echo "&lt;span style='color: red'&gt;An error has occured, your Assessment's new Date and Time have not been updated&lt;/span&gt;"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload