Displaying mySQL data within a web page using PHP

okay as an update. I fixed this line of code below and am now getting this message when accessing http://bobbyrahal.com/connect_test.php (ah_rsvp is the user)

[B]SANITY CHECK

Can’t use foo : Access denied for user ‘ah_rsvp’@‘%’ to database ‘foo’[/B]

This was the code I changed.


<?php

echo 'SANITY CHECK<hr />'; //changed the Quotation mark in "SANITY to 'SANITY



(//changed the Quotation mark in "SANITY to 'SANITY)

Access denied for user ‘ah_rsvp’@‘%’ to database ‘foo’

Well now you are getting to it, at least the error is making some sense now. The user (whose credentials are accepted) does not have access to the database “foo”, which of course does not exist, so what IS the name of the database then - because foo is just a pseudo name.

I think I understand everything from your previous post with the exception of the ‘foo’ variable… what do I put in place of ‘foo’?

Substitute name of your database in both places.

I think we got it! It it showing me this page with a bunch of information…

So what is next?

(Here is a sample of some of the data it pulled up)

PHP Version 5.2.17

System Linux vux6 2.6.37-NETSOL #1 SMP Mon Mar 7 14:56:26 EST 2011 i686
Build Date Mar 7 2011 16:05:34

(//changed the Quotation mark in "SANITY to 'SANITY)
I cant believe I wrote that …


if (!$db_selected) {
    die ('Can\\'t use foo : ' . mysql_error());
}

phpinfo();
?>

Change the above to this now, get rid of the PHP info - I just wanted to make sure PHP was working too, and write a confirmation that you HAVE connected - like so…



// ... as before

if (!$db_selected) {
    die ('Can\\'t use foo : ' . mysql_error());
}else{

echo 'We are connected to the database at last, and we have proved that PHP's Mysql_* extensions are working';
}

?>

Again, replace foo in that message with the name of your database if you wish.

Success!!!

SANITY CHECKWe are connected to the database at last, and we have proved that PHPs Mysql_* extensions are working

So now either reintroduce parts of your original script line by line, hopefully echoing something onto the page actually proving that what you imagine should happening is happening, or just substitute the above connection code and hope for the best.

Don’t forget to remove you actual db credentials from that file and include() them from a directory which is not publicly accessible.