I am currently in the middle of constructing a website for my own personal education to better myselft at work and have encountered a problem.
I am wanting to have the ability to update records located on my database via a form.
This is what I have got so far, am i on the right lines?
Thanks in advance
Edit Book Form
<?php
include 'database_conn.php'; // make db connection
//Get the bookISBN from the request stream
$bookISBN = $_REQUEST['bookISBN'];
//use that code in an sql statement to retrieve the details for the Book
$sql = "SELECT bookISBN bookTitle bookYear bookPrice FROM nbc_book where bookISBN = $bookISBN" ;
//Execute the query
$rsAdmin = mysqli_query($conn, $sql) or die(mysqli_error($conn));
//get the records from the result set into variables
$adminBook = mysqli_fetch_array($rsAdmin);
$bookISBN = $adminBook['bookISBN'];
$bookTitle= $adminBook['bookTitle'];
$bookYear= $adminBook['bookYear'];
$bookPrice= $adminBook['bookPrice'];
//Display those variables in a form
?>
<form action ='editBook.php' method = 'GET'>
<?php
echo "StudentID: $bookISBN<br />";
echo "<input type = 'hidden' name = 'bookISBN' value ='$bookISBN' />";
echo "<input type ='text' name'$bookTitle' value='$bookTitle'>";
echo "Book Title:<input type ='text' name'bookTitle' value='$bookTitle'><br />";
echo "Book Year:<input type ='text' name'bookYear' value='$bookYear'><br />";
echo "Book Price:<input type ='text' name'bookPrice' value='$bookPrice'><br />";
echo "<input type ='submit' value='Save'/>";
mysqli_close($conn);
?>
</form>
Edit Book Process
<?php
// make db connection
include 'database_conn.php';
//Get the bookISBN from the request stream
$bookISBN = $_REQUEST['bookISBN'];
$bookTitle = $_REQUEST['bookTitle'];
$bookYear = $_REQUEST['bookYear'];
$bookPrice = $_REQUEST['bookPrice'];
//construct an SQL Statement
$sql = "UPDATE nbc_books set bookTitle ='$bookTitle', bookYear ='$bookYear, $bookPrice where bookISBN = '$bookISBN'";
//execute the SQL statment
$rsBookUpdate = mysql_query ($bookUpdateSQL);
if ($rsBookUpdate === false) {
echo 'Updating Book failed $bookISBN, $bookTitle failed: ' . mysql_error ();
}
?>
<!--draw link taking them back to books list-->
<a href= "Books.php">Go back to all book records</a>