Hey
This tutorial will show you how to store html form data in a MYSQL database.This tutorial is important for new programmers because new programmers try to store data in text file but text file is just a temporary solution of storing data. But when I need to store data and perform operations on data so we need a database. In this tutorial we are using a MYSQL database. We learn completely from the start. Create html from database php file everything just follow the same steps and try this. Make sure if you want to use MYSQL you need to install MYSQL software. And phpmyadmin(optional). Hope you installed this. Now next step.
In this tutorial we create a simple login form to store data. Let’s start.
Creating a login form now create a new file “login.html”
<html><head><meta charset="utf-8"><title>technogyyan.tech</title><link rel="stylesheet" type="text/css" href="main.css"/><meta name = "viewport" content = "width = device-width, initial-scale=1"></head><body><div align="center"><div class="main_panel"><div><br/><h2>Technogyyan.tech</h2><br/><hr/></div><br/><form action="save.php" method="POST"><br/><br/><label>Name:</label><input type="text" name="name" class="inpt" required/><br/><br/><br/><label>Password:</label><input type="password" name="pass" class="inpt"required/><br/><br/> <br/><input type="submit" class="save_btn" name="submit"/></form><br/><br/></div></div></body></html>
Create a new Css file “Main.css”
.main_panel{width: 40%;background-color:171c24;border: 1px solid black;border-radius: 20px;margin-top: 100px;box-shadow: 5px 5px 5px grey;color: white;}@media only screen and (max-device-width:770px){.main_panel{width:90%;height:50%;border: 2px solid black;border-radius: 20px;}}.inpt{text-align: center;padding: 10px;border-radius: 20px;}.save_btn{background-color:171c24;border-radius: 20px;border: 1px solid white;padding:10px;color: white;width: 100px;}
Now Time to create a Database use sql query to create a database
Create database _Add Database Name_;Example: create database wtsapp;Then create a tableCreate table _Table Name_(col dataType);Example: create tables test(name text,pass text);
Now create a config file for database connection “Config.php”
<?phpdefine("server","localhost");define("username","root");define("password","enter your password");define("database","Enter database name");?>
Create one more file to establish connection “Server.php”
<?phpinclude("config.php");$con = new mysqli(server,username,password,database);//server,username,etc//all is config variable look “config.php”if($con->connect_error){echo("<h1>Error to Connect</h1>");}?>
Now create a last file to store data in database “Save.php”
<?phpinclude("server.php");if(isset($_POST["submit"])){$name = $_POST["name"];$pass = $_POST["pass"];$sql = "insert into test values('$name','$pass')";if($con->query($sql)==true){echo("<script>alert('saved');</script>");}else{echo("<script>alert('not saved');</script>");}}?>
Done. now your form data store in database
One more point if data is stored then how do I see?
Use this Mysql query to see saved data
Connect database_name;//select databaseShow tables;//show all tables listSelect * from _tableName_ ;// using this show all stored data
Follow this tutorial to learn how to store html form data in mysql database or how to send data to server using a php mysql.if you have any problem you can goto “ask me” page or drop comment.
Video Tutorial:
Read also:
Post a Comment