1

I've tried to use ob_start(); and exit(); ,both are not working, please advise, thank you very much

<?php 
    ob_start();

    // connect to the database
    include('connect-db.php');

    // check if the form has been submitted.
    // If it has, start to process the form and save it to the database
    // once saved, redirect back to the view page
    if (isset($_POST["submit"]))
    {
        foreach ($_POST['patientid'] as $index => $patientid)
        {
            $id = mysql_real_escape_string($_POST['id'][$index]);
            $data1 = mysql_real_escape_string($patientid);
            $data2 = mysql_real_escape_string($_POST['vaccineid'][$index]);
            $data3 = mysql_real_escape_string($_POST['vaccinename1'][$index]);
            $data4 = mysql_real_escape_string($_POST['vaccinename2'][$index]);
            $data5 = mysql_real_escape_string($_POST['vaccinename3'][$index]);
            $data6 = mysql_real_escape_string($_POST['totalnoofinjection'][$index]);
            $data7 = mysql_real_escape_string($_POST['nthinjection'][$index]);
            $data8 = mysql_real_escape_string($_POST['date'][$index]);
            $data9 = mysql_real_escape_string($_POST['nextdate'][$index]);
            $data10 = mysql_real_escape_string($_POST['skip'][$index]);
            $data11 = mysql_real_escape_string($_POST['language'][$index]);         

            mysql_query("UPDATE patientvaccinedetail SET patientid = '$data1',
                vaccineid = '$data2', vaccinename1 = '$data3',
                vaccinename2 = '$data4', vaccinename3 = '$data5',
                totalnoofinjection = '$data6', nthinjection = '$data7',
                date = '$data8', nextdate = '$data9', skip = '$data10', 
                language = '$data11'
                WHERE id=$id") or die(mysql_error());

            header("Location: start.php");
            exit;
        }
    }

Just updated and still cant't redirect to another pages

6
  • running on localhost or live ? Commented Jun 22, 2017 at 7:21
  • Please explain what you mean by "not working" Commented Jun 22, 2017 at 7:21
  • 1
    Please stop using mysql_* functions as they are deprecated and completely removed in PHP7! Commented Jun 22, 2017 at 7:25
  • What exactly wasn't working, since it might help future readers. Commented Jun 22, 2017 at 7:27
  • Also its better practice (and more secure) to use parameterized queries instead of concatenating your values into your query string. It also makes your code a bit tidier to boot. Commented Jun 22, 2017 at 7:39

2 Answers 2

3

You are missing semi colon after exit

Corrected code:

exit;

Sign up to request clarification or add additional context in comments.

Comments

1

use ob_end_clean(); before the header call and use exit; instead of exit

try like below

ob_end_clean();
 header("Location: start.php");
exit;

3 Comments

will the exit actually be executed though since the header line redirects to a different page?
Cannot modify header information - headers already sent by (output started at C:\inetpub\wwwroot\June21\displaypatient.php:58) in C:\inetpub\wwwroot\June21\displaypatient.php on line 136
@tam you have echo anything in db connection file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.