Error message

Hi all,

I’m not new to php, however, I am still an amateur. I keep receiving this error " Cannot modify header information - headers already sent by (output…" on my post.php script. Did some research and made some modifications, however, I am still getting the error message. All is fine with the mySQL database, however, the redirect is not working. Perhaps the experts here can help me. Below is the script;

<?php require_once 'config.php'; $fields = array("name", "website", "email", "message"); $isOkay = TRUE; foreach ($fields as $field) { if (empty($_POST[$field])) { $isOkay = FALSE; } } if ($isOkay) { extract($_POST); $now = time(); if (mysql_query("insert into comments (`name`,website,email,message,`timestamp` ) values ('{$name}','$website','$email','$message','{$now}')")) { } else { echo "There was an error connecting to the database!"; } } else { echo "One or more fields are empty!"; } header("Location:http://.............com/guestbook/index.php"); ?>

You have bigger problems. Your code is obsolete and has been completely removed from PHP. You need to use PDO. You are also vulnerable to an SQL Injection Attack.

Trash the code and start with this tutorial: https://phpdelusions.net/pdo

There is no “fixing” your code. Also, dont use extract.

Sponsor our Newsletter | Privacy Policy | Terms of Service