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’]);
<?php
setlocale(LC_MONETARY, 'en_IN');
date_default_timezone_set('Asia/Kolkata');
include "config.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<?php include "head.php"; ?>
<?php include "left.php"; ?>
<div class="parent">
<header class="section header">
MAKES
</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>
</td></tr>
<?php
$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''>
</form></td></tr>";
}
?>
</table></main>
<aside class="section rightSidebar">
<table class="tg">
<?php
if (isset($_REQUEST['edit'])) {
$id=$_REQUEST['id_edit'];
echo "Editing....." .$id;
?>
<table class='tg'><tr>
<td class='tg-h2xt80'>Make Code</td>
<td class='tg-h2xt90'>Make</td>
</td></tr>
<?php
$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'])) {
$id=$_REQUEST['id_edit'];
echo "<td class='tg-n7df'>".$id;
$make=$_REQUEST['make'];
$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']);
//header("Location:makes.php");
echo "</form>";
}
}
if (isset($_REQUEST['delete'])) {
$id=$_REQUEST['id_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));
header("Location:index.php");
exit();
}
?>
</aside>
<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"/>
</form>
</footer>
<?php
if(isset($_REQUEST['save'])) {
$make=$_REQUEST['make'];
$query = "INSERT INTO makes (make) VALUES ('$make')";
mysqli_query($conn,$query)or die ('Unable to execute user_insert.php'.mysqli_error($conn));
header("Location:makes.php");
}
?>
</div>
</div>
</body>
</html>