I want to insert data from a form into a database.
I've searched for a long time but can't figure out what I am doing wrong. Any help will be appreciated
HTML
<!DOCTYPE html>
<html>
<head>
<title>PHP insertion</title>
<link href="css/insert.css" rel="stylesheet">
</head>
<body>
<div class="maindiv">
<!--HTML Form -->
<div class="form_div">
<div class="title">
<h2>Book Information</h2>
</div>
<form action="new 12.php" method="post">
<!-- Method can be set as POST for hiding values in URL-->
<h3>Enter the Details</h3>
<label>Access number</label>
<input class="input" name="access" type="text" value=""><br>
<label>Title</label>
<input class="input" name="title" type="text" value=""><br>
<label>Author</label>
<input class="input" name="author" type="text" value=""><br>
<label>Edition</label>
<input class="input" name="edition" type="text" value=""><br>
<label>Publisher</label>
<input class="input" name="publisher" type="text" value=""><br>
<input class="submit" name="submit" type="submit" value="Submit"><br>
</form>
</div>
</div>
</body>
</html>
PHP
<?php
$link = mysqli_connect("localhost", "root", "admin", "library");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "INSERT INTO library (access,title,author,edition,publisher) VALUES ('$access','$title','$author','$edition','$publisher')";
if(mysqli_query($link, $sql)){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>