0% found this document useful (0 votes)
4 views10 pages

Database Connection Using Mysql

Uploaded by

harshathvb04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Database Connection Using Mysql

Uploaded by

harshathvb04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DATABASE CONNECTION

USING MYSQL
PROGRAM:
(HTML PAGE)
<html>
<head>
<title> Database Connectivity</title>
</head>
<style>
body {
background-image: url('s.jpg') ;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;

}
</style>
<body>
<center>
<font color="white">
<h1> DATABASE CONNECTIVITY </h1>
<br>
<br>
<form action="data.php" method="post">
<b>Name: </b><input type="text" name="name" id="name"><br><br>
<b>RegNo: </b><input type="text" name="regno" id="regno"><br><br>
<input type="submit">
</font>
</center>
</form>

</body>
</html>

(PHP PAGE):
<?php
$name=$_POST['name'];
$regno=$_POST['regno'];
$conn = new mysqli('localhost','root','','register');
if($conn->connect_error)
{
die('Connection failed:'.$conn->connect_error);
}
else{
$stmt=$conn->prepare("insert into datainfo(Name,RegNo)values(?,?)");
$stmt->bind_param("si",$name,$regno);
$stmt->execute();
echo "Registration successful"."<br>";
$stmt->close();
}
$sql = "SELECT Name, RegNo FROM datainfo";
$result=$conn->query($sql);
if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {
echo "<br>"."Name: " . $row["Name"]. "<br>" ."RegNo: " . $row["RegNo"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
OUTPUT

You might also like