What am I doing wrong here. I can't figure out how to make the Update block work. When I hit "Update" button, it goes back to edit.php but with
errors. Errors are: Notice: Undefined variable: POST in C:\xampp\htdocs\libSys\edit.php on line 45
Notice: Undefined variable: POST in C:\xampp\htdocs\libSys\edit.php on line 46
Notice: Undefined variable: id in C:\xampp\htdocs\libSys\edit.php on line 48
Successfully Updated
Lines 45, 46, 48 has
echo $author = $POST['author']; //line 45
echo $isbn = $POST['isbn']; //line 46
$sql = "UPDATE booklist SET Author='$author', Title='title', ISBN = '$isbn' WHERE ID = '$id' "; //line 48
The complete code of edit.php are below:
<?php
include('databaseConnection.php');
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/librarySystem.css">
<title> Edit Book Information </title>
</head>
<div>
<?php
if(isset($_REQUEST['edit'])) //FIRST IF
{
$id = $_REQUEST['edit'];
$sql_select = "SELECT * FROM booklist WHERE ID=$id";
$result=mysql_query($sql_select);
// collect all the data using mysql_fetch_array and assign to our $variables
while($row = mysql_fetch_array($result))
{
$id = $row['ID'];
$title = $row['Title'];
$author= $row['Author'];
$yearLevel = $row['YearLevel'];
$isbn = $row['ISBN'];
}
//displays form for user to edit book information
echo "<form method='POST' action='edit.php'>";
echo "Enter New or Correct Title: <input type='text' name='title' value='$title' > <br />";
echo "Enter New or Correct Author: <input type='text' name='author' value='$author'> <br />";
echo "Enter New or Correct ISBN: <input type='text' name='isbn' value='$isbn' > <br / >";
echo "<input type='submit' name='save' value='Update' > <br />";
echo "</form>";
} //END 1st IF
else if( isset($_POST['save'] ) )
{
echo $title = $_POST['title'];
echo $author = $POST['author'];
echo $isbn = $POST['isbn'];
$sql = "UPDATE booklist SET Author='$author', Title='title', ISBN = '$isbn' WHERE ID = '$id' ";
$result = mysql_query($sql);
if($result == true)
{
echo "Successfully Updated" ;
}
//header('Location: ./booklist.php');
}
?>
How can I correct the update block. It seems to be going to the if(isset($_POST['save']) when I hit "Update" but won't really update the row. Please help. I'm stuck. I don't understand why the "Undefined variable" error pops when I have the variables assigned with $_POST['author']...
I'd appreciate any help or explanation. Thanks.
mysql_*. Usemysqli_*orPDOinstead