SQLTeam.com | Weblogs | Forums

SQL display in PHP?

Hello there,

My name is Chris and I am starting to re-learn SQL after MANY years away from it. Todays "task" is to see if I can display results in a PHP page. The DB and a few tables are set up and working - simple SELECT * FROM Parts query shows exactly what I want. The trouble comes when I try to connect and ultimately display on the PHP page.

I have used the code from a couple of YouTube tutorials made by "Six Minutes Smarter" - sorry, I cant post links here, however here I am referring to his " Connect to MySQL Database with PHP" tutorial.

I have no idea whether my "display-data.php" page works as yet because everything falls down in the "connect" page I mention above. The code as per the tutorial is as follows. Note that for this post, I have changed the user, password, and name attributes as I am assured by the hosting provider that these are correct... so don't worry; the password isn't really "password"! :slightly_smiling_face:


Define ('DB_USER', 'database_user');
DEFINE ('DB_PSWD', 'password');
DEFINE ('DB_NAME', 'database');

$dbCon = mysqli_connect (DB_HOST, DB_USER, DB_PSWD, DB_NAME);

if (!$dbcon) {
die ('error connecting to database');
echo 'you have connected successfully';


The script runs fine, but I just get the "error connecting to database" message.
I have checked with my hosting provider that the other details (i.e. the host) are all correct; which they are. They suggest that instead there is something not quite right with the code itself. Which is great but for the life of me I can't work it out!

Many thanks for your time, and sorry for a long first post! Look forward to hearing if anyone can help.



This forum is neither a MySql nor a php forum but. Check following