0

Here is my code:

    $id = $_GET['id'];
$data = $_POST['name'];
$data1 = $_POST['id'];
$c = 0;

foreach ($data1 as $key => $value) {
    $sql = "UPDATE ".$table_comp." SET score = " . $data[$c][$value] . " where id = " . $value .";" ;
    mysqli_query($connect,$sql);
    $c++;
} 
header('Location: http://www.csscorecard.com/admin/?id=$id');

I have problem in my redirect there is an error:

Warning: Cannot modify header information - headers already sent by (output started at /home/csscorecard/public_html/wp-content/themes/twentyseventeen/ajax/submit.php:3) in /home/csscorecard/public_html/wp-content/themes/twentyseventeen/ajax/submit.php on line 54

chris85
  • 23,846
  • 7
  • 34
  • 51
Leorah Sumarong
  • 107
  • 4
  • 16

3 Answers3

1

use javascript instead of headers.

you can use this code to redirect

<?php

echo "<script>window.location.href = 'http://www.csscorecard.com/admin/?id=".$id."'</script>";

?>
Enstage
  • 2,106
  • 13
  • 20
  • 1
    If we post the form using javascript then only we can use this..writing javascript in PHP script is not a valid way...`header` facilitates to Send a raw HTTP header – Nidhi Jun 08 '17 at 05:05
  • you are right @Nidhi, but he's seems to sending request through ajax. – Divyank Munjapara Jun 08 '17 at 06:09
0

Its quite complex to give answer in this case without seeing whole file code. In many cases this error shown. but for header location you should put exit:

exit(header("Location: http://www.csscorecard.com/admin/?id=$id"));
Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
0

You can add ob_start(); top of the file

Farhad Hossen
  • 263
  • 1
  • 6