Nisanth
Nisanth

Reputation: 333

how to reload the same page while click delete button in php - moodle

I want to reload the same page while i am clicking delete button. The delete button action is working but the page is not reloaded. how to solve this issues.

I am trying the following code :

 if($delete){

    $del = delete_records('mastercourse',$field='id',$value=$delete);
   location.reload();

}

Upvotes: 1

Views: 1421

Answers (2)

Nisanth
Nisanth

Reputation: 333

Just add Redirect() like below :

if($delete){

$del = delete_records('mastercourse',$field='id',$value=$delete);

redirect($CFG->wwwroot."/viewfile.php");

}

Here viewfile.php is the file name to redirect.

Upvotes: 1

Thamilhan
Thamilhan

Reputation: 13313

You are embedding javascript inside PHP, so enclose with tags

echo "<script>location.reload()</script>";

or if you want to redirect: (from discussion)

echo "<script>location.href='viewfile.php'</script>";

alternatively, can use PHP's

header("Refresh:0");

Upvotes: 1

Related Questions