r/PHPhelp • u/italrose • Aug 14 '20
Getting data from PHPMyAdmin (beginner question)
I've not touched PHP in 15 years or so (and the last time I was a beginner at best) so I'm a bit rusty.
My problem is I have a database (called table1) with a table in that has two data rows and when I try to select the info from the db to a PHP-page it successfully establishes the collection but doesn't seem to pull any data from the db.
I've got some server space through one.com where I have a database.
My issue is that I don't understand why it doesn't process my SQL. I've uploaded the super basic page (as a .txt) where I try this in hope that someone can identify where I go wrong. Username, password etc are changed (connection is successful so the issue doesn't seem to be there).
https://1drv.ms/t/s!AhzkfwJlWNPrhbIKlzv6JoRrXoGQ0w
I've got my page one a server hosted by one.com using PHP 7.4 and PHPMyAdmin if that information is important.
4
u/twistdafterdark Aug 14 '20 edited Aug 14 '20
I think you're missing the database name in the conn
$conn = new mysqli($servername, $username, $password);should be
$conn = new mysqli($servername, $username, $password, $databasename);Then
$sql = "SELECT * FROM <tablename>";replace<tablename>with the actual tablename instead of the databasenameEdit:
On a different note, you should look into MVC framework and move the database connections to a separate file instead of directly in your html template.
Here's a Build a PHP MVC Application playlist that gives a decent explanation on it.