Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP is not reloaded automatically after processing
    primarykey
    data
    text
    <p>Hi I have a PHP file with data. The value is passed on to another php file which process it successfully. But the first php file does not refresh to update the new result. It have to do it manually. Can any one tell me where I'm wrong or what needs to be done. Please find my code below. </p> <p>PHP code (1st page, index.php)</p> <pre><code>function display_tasks_from_table() //Displayes existing tasks from table { $conn = open_database_connection(); $sql = 'SELECT id, name FROM todolist'; mysql_select_db('todolist'); //Choosing the db is paramount $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } echo "&lt;form class='showexistingtasks' name='showexistingtasks' action='remove_task.php' method='post' &gt;"; while($row = mysql_fetch_assoc($retval)) { echo "&lt;input class='checkbox' type='checkbox' name='checkboxes{$row['id']}' value='{$row['name']}' onclick='respToChkbox()' &gt;{$row['name']} &lt;img src='images/show_options.gif' /&gt;&lt;br&gt;"; } echo "&lt;/form&gt;"; echo "&lt;label id='removeerrormsg'&gt;&lt;/label&gt;"; close_database_connection($conn); } </code></pre> <p>Javascript code which finds the selected value:</p> <pre><code>var selVal; //global variable function respToChkbox() { var inputElements = document.getElementsByTagName('input'), input_len = inputElements.length; for (var i = 0; i&lt;input_len; i++) { if (inputElements[i].checked === true) { selVal = inputElements[i].value; } } } </code></pre> <p>jQuery code which passes value to another page (remove_Task.php):</p> <pre><code>$(document).ready(function() { $(".checkbox").click(function(){ $.ajax({ type: "POST", url: "remove_task.php", //This is the current doc data: {sel:selVal, remsubmit:"1"}, success: function(data){ //alert(selVal); //console.log(data); } }); }); }); </code></pre> <p>PHP code (2nd page, remove_task.php);</p> <pre><code>session_start(); error_reporting(E_ALL);ini_set('display_errors', 'On'); $task_to_remove = $_POST['sel']; function remove_from_list() //Removes a selected task from DB { $db_connection = open_database_connection(); global $task_to_remove; mysql_select_db('todolist'); $sql = "DELETE FROM todolist WHERE name = "."'".$task_to_remove."'"; if($task_to_remove!='' || $task_to_remove!=null) { mysql_query($sql, $db_connection); } close_database_connection($db_connection); header("Location: index.php"); } if($task_to_remove != "") { remove_from_list(); } </code></pre> <p>The selected value is getting deleted but the display on index.php is not updated automatically. I have to manually refresh to see the updated result. Any help would be appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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