in PHP using MYSQL

0


A database is used to store information permanently under the system harddisk or server machine.
A database contains a set of tables to store data, Table contains a set of rows and columns. rows represent records and columns represent the field.
for example, if we want to store Student Record  then first we create a database then create a table  and column according to requirement  (rno,sname,branch, fees,mobile)
PHP provides PHPMyAdmin software tools to work in MYSQL Database.
How we open PHPMYADMIN:-
open the XAMPP Control Panel and Click on MySQL Button to start.
1)  Create Database to click on Databases and create table and column using PHPMyAdmin now I am creating database php12btach and table student with following columns
(rno,sname,branch, fees,mobile)
2)  Create Form According to the table in PHP using HTML elements
3) Write Database Connectivity Code
     3.1)   Create a Connection String
               mysqli_connect('localhost','root','','databasename');
   3.2)    Write Code for Insertion
             mysqli_query("insert into tablename (column1,colum2,colum3,...) values('value1','value2','value3','value4'),")
Complete Code for Database Data Insertion
Design part using PHP:-
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="InsertStu.php" method="post">
<input type="text" name="txtrno" placeholder="Enter rno" />
<br>
<br>
<input type="text" name="txtsname" placeholder="Enter name" />
<br>
<br>
<input type="text" name="txtbranch" placeholder="Enter branch" />
<br>
<br>
<input type="text" name="txtfees" placeholder="Enter fees" />
<br>
<br>
<input type="submit" name="btnsubmit" value="Insert">
</form>
</body>
</html>
Code for InsertStu.php
<?php
$r = $_REQUEST['txtrno'];
$n = $_REQUEST['txtsname'];
$b = $_REQUEST['txtbranch'];
$f = $_REQUEST['txtfees'];
$conn=mysqli_connect('localhost','root','','php12batch');
$res= mysqli_query($conn,"insert into student (rno,sname,branch,fees) values('$r','$n','$b','$f')");
if(mysqli_affected_rows($conn)>0)
{
echo "data inserted successfully";

}
else
echo "problem in insertion";

?>
Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)