Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

How to insert the record in PHP and MYSQL database?

How to insert the record in PHP and MYSQL database?

In this tutorial, we will try to learn the insertion of records in the database table in PHP and MySQL.

Code of insertion of records in the database table in PHP and MySQL

<?php
mysql_select_db('publisher',mysql_connect('localhost','root',''));
?>
<html>
<body>
<form method="post">
<table>
<tr><td>Title:</td><td><input type="text" name="TextBoxForTitle"></td></tr>
 <tr><td><input type="submit" name="submit" value="add"></td></tr>
</table>
</form>
<?php
if (isset($_POST['submit'])){
$TitleVariable=$_POST['TextBoxForTitle'];
mysql_query("insert into books (BookTitleAttribute) values('$TitleVariable')");
header('location:index.php');
}
?>
 </body>
</html>

Line 6: Form method as post enables the form to send the values from form to the database.

Line 13:  Ensuring that form is able to successfully post the values to the database or not?

Line 14: Value that is entered in the textbox named as  “TextBoxForTitle” is handed over to the variable  “$TitleVariable”.

Line 15: mysql_query() function is responsible for success execute the MySQL query. According to the mentioned query data can be inserted into the attribute of table “books”. The attribute is “BookTitleAttribute”. The value that is entered by the user, stored in the attribute “BookTitleAttribute”.

Database

Database insert delete view update in php mysql

Figure: Database insert delete, view update in PHP, My SQL.

Prof. Fzal Rehman Shamil
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325