Database connectivity in PHP using MYSQL:-

 1) SQL Introduction:-

2) Database connectivity in PHP with MariaDB:-

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

   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>
<form action="InsertStu.php" method="post">
<input type="text" name="txtrno" placeholder="Enter rno" />
<input type="text" name="txtsname" placeholder="Enter name" />
<input type="text" name="txtbranch" placeholder="Enter branch" />
<input type="text" name="txtfees" placeholder="Enter fees" />
<input type="submit" name="btnsubmit" value="Insert">

Code for InsertStu.php

$r = $_REQUEST['txtrno'];
$n = $_REQUEST['txtsname'];
$b = $_REQUEST['txtbranch'];
$f = $_REQUEST['txtfees'];
$res= mysqli_query($conn,"insert into student (rno,sname,branch,fees) values('$r','$n','$b','$f')");
echo "data inserted successfully";

echo "problem in insertion";


Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post