0

I have wriiten as

<?php
  if (isset($_POST['delete'])):
    $size = count($_POST['checkbox']);
    for ($i=0; $i<=$size-1; $i++) {
    $id = $_POST['checkbox'][$i];
    $wpdb->query("DELETE FROM wp_submitted_form WHERE id =".$id);
    }
   header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  endif; 
?>

When submit button is clicked it throws error message as:

Cannot modify header information - headers already sent by (output started at /home/wizcorea/public_html/wp-admin/includes/template.php:1657) in /home/wizcorea/public_html/wp-content/plugins/submitted-form/view.php on line 54

I want that page should get refreshed after submit button is clicked

Konsole
  • 3,447
  • 3
  • 29
  • 39
Nida
  • 1,672
  • 3
  • 35
  • 68
  • 1
    if you had just spent 1 minute searching for "headers already sent php" you would have found thousands of results, with very good answers to that. see here: http://stackoverflow.com/search?q=headers+already+sent+php – x4rf41 Aug 07 '13 at 10:00

1 Answers1

0

Use the ob_flush function of PHP. add this function at the top of the code.

<?php

ob_flush();

And this will work.

EDITED:

INstead of this code:

header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);

Use this code:

echo '<script>location.href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'"</script>';
Code Lღver
  • 15,573
  • 16
  • 56
  • 75