+ 1
How to connect database with your web page with php
5 Answers
+ 1
Do you use XAMPP ? If yes then turn on mysql in xampp control panel.
After that creat php file you can name it anything like conn.php
Then type
<?php
$servername =Â "localhost";
$username =Â "username";
$password =Â "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}Â
echo "Connected successfully";
?>
if you not set any username/password into your local db then set the value blank ("")
+ 1
What should i do now
+ 1
I think i have server problem its still not working
0
i did what you said but when i submit my data on web page then it doesn't enter the data in my database but ut shows the php code
0
Oke then lets try this.
Edit the code before for conn.php, give another string for database name $dbname
<?php
$servername =Â "localhost";
$username =Â "";
$password =Â "";
$dbname = "the name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}Â
echo "Connected successfully";
?>
then put this php code into your main page / index.php
<?php
include 'conn.php';
$conn = OpenCon();
echo "Connected Successfully"; CloseCon($conn);
?>
this will print on you screen 'Connected Successfully' for testing is your connection from conn.php works or not