How To Connect Website With the Database using PHP Language
While creating websites is very useful today as it help us
to do business by making e-commerce websites, showing online information for
our businesses like static websites etc. for making e-commerce websites you
need to have a databases for storing information about the products and all
users who might signup or purchased anything from the websites. Databases plays
very crucial role when your website need to store information whatever it is
like user information such as signup, information for products or simple form
for getting information about survey or anything like that. We have created
database for our sample website we will use PHP language for connecting and manipulating
our created databases by inserting information, updated and deleting
information from the table. For submitting information to the website we need
to connect backend with front end we will use PHP Language for connection
establishing we need to call mysqli object of php language which connect the
front end with the backend it have different parameters such as hostname for
Xampp we have Localhost as a hostname and for Username we have Root and we
might not use Password as we don’t have it and for Database Name you must use
the name of your created DB such as we have created and use CS_Dep in our Lab
example showing PHP CODE such as:
$con=new mysqli("Hostname","Username","Password","DatabaseName");
For inserting information coming from the website you need a
method to get the variable for instant we have use POST method in our website as
shown below:
<form action="db_connection_insert.php"
method="POST">
User Name: <input type="text"
id="name" name="name" placeholder="Enter your
name" >
Password: <input type="password"
id="pass" name="pass" placeholder="Enter your
password">
<input
type="submit" id="sub" name="sub" >
</form>
In this we have define action it means when user click on
the submit button all information such as name and pass we send to the
db_connection_insert.php file with using method POST so in php file we will get
this information and store in variable using this code:
$name=$_POST["name"];
$pass=$_POST["pass"];
After that well use then for inserting into our table in which
we want to insert so we need to SQL query for that we will write Query and Execute
it using this code:
$q="update def set pass='".$pass."' where
username='".$name."'";
$results=$con->query($q);
For checking information has inserted successfully or not we use conditional statement:
if($results==TRUE)
echo
"Sucess data inserted";
else
echo
"Error Data is not inserted";
$con->close();
File HTML:
<html>
<head>
<title>
Peep Grams
</title>
</head>
<body>
<p> Please provide information </p>
<form action="db_connection_insert.php" method="POST">
User Name: <input type="text" id="name" name="name" placeholder="Enter your name" >
Password: <input type="password" id="pass" name="pass" placeholder="Enter your password">
<input type="submit" id="sub" name="sub" >
</form>
</body>
</html>
$con=new mysqli("localhost","root","","cs_dep");
$name=$_POST["name"];
$pass=$_POST["pass"];
$q="insert into def values('".$name."','".$pass."')";
if($con->query($q)==TRUE)
echo "Sucess data inserted";
else
echo "Error Data is not inserted";
$con->close();
?>
Task For this Lab :
As you guys already familiar with how to upload your website on the 000webhost now you guys will create your database online on the 000web host as i did last time and connect it to the website and see how it works:
For Database Creation follow the easy Steps:
1) login to the 000web click on the manage website button you will find interface like this:
2) go down and find the Database section Like this you can create your database online using Database option and after creating you can manage it my using phpmyadmin for creating tables in the database online :
3) After that upload php file and html file in the same directory online as we have done it before.
Congratulations you have done it.
https://minuscular-decoder.000webhostapp.com/
ReplyDeleteMuhammad Usama Bin Rehan
Storing Login information into database through web page.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletehttps://thepero.000webhostapp.com/
ReplyDeleteAssalam o Alaikum SIR G:
Muhammad Azeem Qureshi.
Storing Login information into database through web page
This comment has been removed by the author.
ReplyDeletehttps://my-webdevelopment.000webhostapp.com/
ReplyDeleteMuhammad Salman
Welcome to Web development
Php connected to database to insert information
https://ayeshaarazzaq.000webhostapp.com/
ReplyDeleteAyesha Razzaq
***********My Lastest Website**********
ReplyDeletehttps://the-shadows.000webhostapp.com/
Muhammad Arslan Tariq
Now I Have Added New Feature in My Website.
Now Your Login Information is Being Stored into Database through Web Page.
Your Personal Data Is Guaranteed Secured.
You Can Also Contact Me On Facebook,Insta,Twitter by Clicking Given Links On My Website.
Soo You Can Trust On Shadow Hackers Team and Login Now...!
After Following steps given in blog
ReplyDeleteFinlay i have done my class project
Thnx to PeepGrams.....!!!
Post a Comment