+ 1

How to connect database with your web page with php

17th Apr 2019, 5:16 AM
Anchal Paswan
Anchal Paswan - avatar
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 ("")
17th Apr 2019, 12:02 PM
Andri Hry
Andri Hry - avatar
+ 1
What should i do now
17th Apr 2019, 1:23 PM
Anchal Paswan
Anchal Paswan - avatar
+ 1
I think i have server problem its still not working
17th Apr 2019, 1:48 PM
Anchal Paswan
Anchal Paswan - avatar
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
17th Apr 2019, 12:26 PM
Anchal Paswan
Anchal Paswan - avatar
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
17th Apr 2019, 1:36 PM
Andri Hry
Andri Hry - avatar