+1

How to connect database with your web page with php

4/17/2019 5:16:48 AM

Anchal Paswan

5 Answers

New Answer

+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 ("")

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

What should i do now

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

0

I think i have server problem its still not working