AsSalam and hi all.
Thsi is the 2nd part basic tutorial on how to connect your PHP file to databased and display data from the selected table. The 1st part of the tutorial is where we create online MySQL databases from cPanel. You should ensure have the databased ready before start this tutorial.
- 1st, go to cPanel home and in FILES section, select File Manager.
- Ensure you are in public_html folder as this consider the root for your hosting.
- In this example, I create a folder name datafromdb in an example folder. Therefore, my path will be https://dewasolutions.com/example/datafromdb
- Then, click on +File button and create an php file, click Create New File button.
- Check the webpage, now we have an empty blank page as below.
- Next, select the php and click on Edit button. Edit popup window will appear, click on Edit button.
- Line 2: create the connection to databased (host , user , password, databased).
- Line 4: check the connection.
- Line 9: select data from databased table dataSaya.
- Line 17 – 23: Looping to fetch all data from table and display it.
- Click on Save Changes button and refresh your webpage.
- We should now get the data form table displayed on our webpage.
That’s it. Now you should have a webpage display data from online MySQL databased. InsyaAllah in the next basic tutorial, we will create a form to insert data, edit data and removed data.