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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php $conn = mysqli_connect('localhost','root','','publisher');?> <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']; mysqli_query($conn, "insert into books (BookTitleAttribute) values('$TitleVariable')"); header('location:insert.php'); } ?> </body> </html> |
Code of insertion of records in the database table in PHP by using MySQL and without MySQLi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?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
Code of insertion of records in the database table in PHP Using MySQLi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $conn = mysqli_connect('localhost','root','','publisher');?> <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']; mysqli_query($conn,"insert into books (BookTitleAttribute) values('$TitleVariable')"); header('location:index.php'); } ?> </body> </html> |
Value Move Graph of Program of insert values in PHP
Video Lectures
how to insert data in MySQL using PHP.
insert data from form to MySQL database PHP.
how to insert data into MySQL db using the form in the PHP database.
insert form data into a database using PHP.
PHP insert data into MySQL.
how to create an HTML form that stores data in a MySQL database using PHP.
how to save data from HTML form to a database using PHP.
how to insert multiple rows in MySQL using PHP form.