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";

?>

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response