It seems like a proper method. It shows all the messages and displays. But it doesn't show up i the actual mysqli database. Can someone help me find out where it is going wrong? HTML input is getting read into the PHP part and everything is going well except the part where it does not show up in the database.
Thanks in advance!
<!DOCTYPE html>
<html>
<?php
$con = mysqli_connect("localhost","root","","bookstore"); // Establishing Connection with Server
echo 'Connected to database...';
$Title = $_POST['Title'];
$Author = $_POST['Author'];
$Price = $_POST['Price'];
$StateOfCopy = $_POST['StateOfCopy'];
echo 'Data posted...';
//Insert Query of SQL
$sql = "INSERT INTO bookstore.booklist (`Title`, `Author`, `Price`, `StateOfCopy`)
VALUES ('B10037', 'Children', $Title, $Author, $Price, 'Faerie Publishers','P10012', $StateOfCopy)";
echo $Title;
echo $Author;
echo $Price;
echo $StateOfCopy;
// mysql_close($connection); // Closing Connection with Server
/*
INSERT INTO bookstore.booklist (`BookID`, `Category`, `Title`, `Author`, `Price`, `Publisher`, `PublisherID`, `StateOfCopy`)
VALUES ('B10036', 'Children', 'The Snow Queen', 'Hans Christian Anderson', 23.84, 'Faerie Publishers', 'P10012', '1st edition, Binded')
*/
if($con->query($sql) === TRUE)
{
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else
{
echo "Error: ".$sql."<br>".$con->error;
}
$query = "SELECT * FROM bookstore.booklist";
$result = mysqli_query($con,$query);
$num = mysqli_num_rows($result);
echo $num;
?>
<head>
<title>PHP insertion</title>
</head>
<body>
<div>
<!--HTML Form -->
<div>
<div>
<h2>Insert Data In Database Using PHP.</h2>
</div>
<form action="insert.php" method="post">
<!-- Method can be set as POST for hiding values in URL-->
<h2>Form</h2>
<label>Title:</label>
<input class="input" name="Title" type="text" value="">
<label>Author:</label>
<input class="input" name="Author" type="text" value="">
<label>Price:</label>
<input class="input" name="Price" type="text" value="">
<label>State of Copy:</label>
<input class="input"name="StateOfCopy" type="text" value="">
<br>
<input name="submit" type="submit" value="Insert">
</form>
</div>
</div>
</body>
</html>