Translate

 HOW TO CONNECT DATABASE IN PHP FULL SOURCE CODE WITH EXAMPLE:

Databaseform.html

<!DOCTYPE html>
<html>
<head>
<title>
SHAURYA</title>
</head>

<body style="background-color:pink">




<h1 style="margin:auto;color:blue;text-align:center"> SHAURYA</h1>
<br><br><br><br><br><br>


<form name="Nameform" action="database4.php" method="get">
<!-- <form action="myphp.php" method="get"> -->
Enter eid:<br>
<input type="number" name="eid"><br>
First name:<br>
<input type="text" name="ename"><br><br>
<input type="submit" value="submit">
</form>

</body>
</html
Databasetest.php
<?php 
$servername="localhost";
$username="root";
$password="";
//connection to mysql
$conn=mysqli_connect($servername,$username,$password);
if(!$conn)
{
die("Connection Failed".mysql_error());
}

//Create database
$sql="CREATE DATABASE lname";//change name to change database

if( mysqli_query($conn,$sql) )
{
echo ("Database create successfully");
}
else
{
echo ("Error Creating Database".mysqli_error());
}
mysqli_close($conn);
?>
Databasetry.php
<?php
$servername="localhost";
$username="root";
$password="";

$conn=mysql_connect($servername,$username,$password);
if(!$conn)
echo "Error in Connection".mysql_error();

$dbcheck=mysql_select_db("lname");
if(!$dbcheck)
echo "Error selecting Database<br>".mysql_error();
//else echo "Success";

//mysql_close($conn);

?>

Post a Comment

Previous Post Next Post