Jump to content

how to reload a page after an update is made to a database


Darkmatter5

Recommended Posts

Here's my update code

          <?php
            if(isset($_POST['editjob'])) {
                include 'library/dbconfig.php';
                include 'library/opendb.php';
                
                //handling textboxes
                foreach (array('job_number','job_desc','job_loc','section','lot_blk','fb_pg','fnd_date','acerage','memo_info','vol_pg','estimate','amount','assign_date','completion_date') as $field1) {
                    if ($_POST[$field1]) {
                        $data[]=$field1. "=" ."'{$_POST[$field1]}'";
                    }
                }
                //handling dropdown lists
                foreach (array('client_id','county_id','survey_id_1','survey_id_2','survey_id_3','subdivision_id','type_id_1','type_id_2','type_id_3','employee_id') as $field2) {
                    if ($_POST[$field2]!="---Select---") {
                        $data[]=$field2. "=" ."'{$_POST[$field2]}'";
                    }
                }
                //insert data into table
                foreach ($data as $value) {
                    $updatedata="UPDATE $dbname.jobs SET $value WHERE job_id='{$_POST['job_id']}'";
                    mysql_query($updatedata) or die(mysql_error() .": $updatedata");
                }
                
                //echo "Job " .$_POST[job_number]. " UPDATED to jobs table...";
            
                include 'library/closedb.php';
                header("Refresh: url='{$_SERVER['PHP_SELF']}?job_id={$_POST['job_id']}'");
            }
        ?>

 

I've read up on the header function and it says in PHP 4.0 and up you can use Output Buffer to get past the restriction of using header after other data has been output to the page.  How do I do this?  How do I use header and output buffering to accomplish this?

Don't do it.  If you need to do it then there is probably a better way to structure your code.

 

But if you must...

 

<?php
// call this at the beginning
ob_start();

// output anything you want here, it won't go to the browser...
echo 'lolololz';

// grab the output at the end of the script
$output = ob_get_flush();

// either echo the output or do a header redirect
echo $output;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.