Help in update

Please help and thanks in advance!
my table is called makes, with coloums -->makeCode int(5) auto increment & Primary Key, make char(32), make_status(6).

I can insert and delete data as required. , however header(“Location:index.php”); in if(isset($_REQUEST[‘delete’])) {… does not take me to index.php

Main Issue is with editing , data is not storing.
in error log I am getting PHP Warning: Cannot modify header information - headers already sent…
on account of header('Location: ’ . $_SERVER[‘PHP_SELF’]);

setlocale(LC_MONETARY, 'en_IN');
include "config.php";
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css">
<div class="container">
<?php include "head.php"; ?>
<?php include "left.php"; ?> 
    <div class="parent">
    <header class="section header">
<main class="section main">
<table class='tg'><tr>
    <td class='tg-h2xt80'>Make Code</td>
    <td class='tg-h2xt90'>Make</td>
    <td class='tg-h2xt90'>Action</td>
$sql = "SELECT * FROM makes WHERE make_status is NULL ORDER BY makeCode";
$result=mysqli_query($conn, $sql);
while ($row= mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td class='tg-n7df'>" .$row['makeCode']. "</td>";
    echo "<td class='tg-0pky'>" .$row['make']. "</td>";
    echo "<td class='tg-dvpl'><form class='new' action= ''  method='POST'>
<input type='hidden'  name='id_delete'  value=" .$row['makeCode']. ">
<input type='submit'  class='cancelbtn1' name='delete' value='DEL''>
<input type='hidden'  name='id_edit'  value=" .$row['makeCode']. ">
<input type='submit'  class='blue-thin' name='edit' value='EDIT''>
<aside class="section rightSidebar">
<table class="tg">
if (isset($_REQUEST['edit'])) {
    echo "Editing....." .$id;
<table class='tg'><tr>
    <td class='tg-h2xt80'>Make Code</td>
    <td class='tg-h2xt90'>Make</td>
    $query="SELECT * from makes WHERE makeCode='$id'";  
    $result = mysqli_query($conn, $query) or die ('Unable to execute query quotea.php'.mysqli_error($conn));
    while ($data=mysqli_fetch_assoc($result)) {
echo "<form name='update action= ' ' method='POST'>";
echo "<td class='tg-n7df'>" .$data['makeCode'];
echo "<td class='tg-0pky'><input name='make' value=".$data['make'].">";
echo "</table>";
echo "<input class='blue'  type='submit' name='update' value='Update' />";
echo "<input class='red' type='reset'  name='Reset' value='Reset'/>";

if(isset($_REQUEST['update'])) {
    echo "<td class='tg-n7df'>".$id;
    $query = "UPDATE makes SET  make='$make' WHERE makeCode=$id";
    echo "Updated......." .$make .$id;
    mysqli_query($conn,$query) or die ('Unable to execute makes.php'. mysqli_error($conn));
    //header('Location: ' . $_SERVER['PHP_SELF']);
echo "</form>"; 
if (isset($_REQUEST['delete'])) {
    $query = "UPDATE makes SET  make_status='DEL' WHERE makeCode='$id'";
        mysqli_query($conn,$query) or die ('Unable to execute makes.php'. mysqli_error($conn));

<footer class="section footer ">
<form name="user" action=""  method="POST"> 
<label>Make</label><input type="text" name="make"  />

<input class='blue'  type=submit name="save" value="Save" />
<input class='red' type=reset  name="Reset" value="Reset"/>
if(isset($_REQUEST['save'])) {

$query = "INSERT INTO makes (make)  VALUES ('$make')";

mysqli_query($conn,$query)or die ('Unable to execute user_insert.php'.mysqli_error($conn));


Post method form processing code must be located above the start of the html document so that nothing is being output to the browser before the header() statements.

Add this to the top of your PHP page.

@katsry, please don’t suggest adding output buffering to hide problems in code.

The OP has several problems, only one of which is a header() redirect that isn’t working in a part of the code that is actually running. By rearranging the code as has been suggested, which will simplify it, the OP may be able to see the mistakes in the html markup and two logic problems that are preventing the update code from working. Simpler is always better and hiding problems doesn’t make them go away.

@phdr if this was my project, I would edit this code to make it work perfectly without any “headers already sent” error.
Remember, they’re a lot of variables that can cause that error no matter your solution. Believe me, I have tried that.
The situation here is a solution. That provides a solution.

“As long as it works” is not a solution. It is just a hack to hide the real problems.

this is what got it working

Sponsor our Newsletter | Privacy Policy | Terms of Service