how to insert data in database using php and mysql |
What is PHP?
PHP stands for hypertext pre processor which is another famous server side scripting language which is used for creating dynamic websites and online as well as desktop applications.
PHP is a open source language which exactly means it is absolutely free to use and modify. The scripts written in PHP tends to execute faster compared to another programming.
PHP Language is basically used with database language with MYSQL which is more compatible with PHP.
PHP is on the other hand quite simple to learn and execute where new students and professional are using this language to some extend.
Also Read
- https://12techtipsandtricks.blogspot.com/explain-sql-statement-with-examples
- https://12techtipsandtricks.blogspot.com/what-is-computer
What is MYSQL?
SQL stands for structural query language or sequential query language.
MYSQl is database programming language which is very famous in new programmers as well as pro software developer who are working online as well as offline to create customized online and offline applications.
SQl can handle big data with ease with php can one of the bigger projects and online applications are developed with PHP and MYSQl.
Example :: Facebook.com
Now lets start with..
- create database in the name of practice
- create table in side the database in the name of students
- create fields name,lastname and address
- name=varchar
- lastname=varchar
- address=varchar
html code to create form and fields
- <html>
- <head>
- <body>
- <table>
- <tr>
- <th>Name</th>
- <th>Lastname</th>
- <th>Address</th>
- </tr>
- <tr>
- <input type="text" name="name" id="name">
- </tr>
- <tr>
- <input type="text" name="lastname" id="lastname">
- </tr>
- <tr>
- <input type="text" name="address" id="address">
- </tr>
- </table>
- <input type="submit" name="save" id="save" value="save">
- </body>
- </head>
- </html>
create a PHP file in the name save.php write the code given below
<?php
//database connection
$conn=new mysqli ("localhost","root","","practice") or die("Unable to connect to database");
if(isset($_POST['save'])){
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$query="insert into students set name='$name',lastname='$lastname',address='$address'";
$run=$conn->query($insert);
if($conn->query($run)){
echo "<script>alert('Topic Saved Successfully')</script>";
}
}
?>
Read More
Comments
Post a Comment