Here is one more example php program to add new records to a table, try it out
Before you execute the program, run this query in MySQL to create the table
create table book(Acc_no INTEGER(20),Title varchar(50),Author varchar(50),Publisher varchar(50),Edition INTEGER(3));
HTML Code:
<html>
<head><title>Deatails</title></head>
<body>
<form action = "phpfile.php" method=”post”>
<h1>ENTER DETAILS</h1>
ACCNO<input type="text"name="Acc_no"> <br>
<br>
TITLE<input type="text"name="Title"> <br>
<br>
AUTHOR<input type="text"name="Author"> <br>
<br>
EDITION<input type="text"name="Edition"> <br>
<br>
PUBLICATION<input type="text"name="Publisher"> <br>
<br>
<input type="submit"value="SUBMIT">
<input type="reset"value="CLEAR">
</form>
</body>
</html>
PHP Code:
<?php
header('content-type:text/plain');
$db=mysqli_connect('localhost','newuser','password','test');
if(!$db){
die('Could not connect:');
}
$sql="insert into book (Acc_no,Title,Author,Publisher,Edition)".
"values('$_REQUEST[Acc_no]',".
"'$_REQUEST[Title]','$_REQUEST[Author]',".
"'$_REQUEST[Publisher]','$_REQUEST[Edition]');";
mysqli_select_db($db,'test');
$retval=mysqli_query($db,$sql);
if(! $retval){
die('Could not insert values');
}
echo "Record Insertion Successful";
?>