PHP – Insert Form Data Into MYSQL Database Using PHP
Today I will show you How to insert Form Data in Mysql Database Using PHP. First I will create a Database as a Tutorial create Database is created as you can see Database tutorial Now I will create one table as a person First column ID type integer and it will be auto increment when we use auto increment mode we don’t have to insert any value the value is inserted automatically by MYSQlL Second Column Name type varchar and length 20 third Email type varchar again length 20 save table is also created let’s check Database tutorial person as you can see ID is auto increment name as varchar email now I will create HTML Form Html head title Insert Form Data In MYSQL Database using PHP end, title end, head, body end, body end, HTML. I will save it as an index.
HTML now I will create one form action=”inset.php” Insert.php page will contain our PHP script to insert data into Mysql Database method=”POST” you can also use get when we use get method the data is visible unique URL the name attribute is required when we have to use this data in PHP the break line
Submit button input type=submit value=”Insert” end form now HTML form is ready now I will create PHP script I will save it as an insert.
php first i will crete conncetionj for Databse $ sign is used to declare variable $con = mysqli_connection(‘127.0.0.1′,root”,”); 3 parameters is required user name ass root i.e default check for connection if not echo echo is used to print string now select Database mysqli_select_db($con,’tutorial’) now i will get the value send from the index.
html Email = $_POST[’email’]; sql Command INSERT INTO person (Name,Email) VALUE (‘$Name’,’$Email’) mysqli_query($con,$sql) echo “Inserted”; Page should be redirected to index.html after insertion for this i will header(“refresh:2; url=index.