![]() |
PHP/SQL Help Please
Hi Guys,
I'm trying to use the following PHP code to query some entries in a MySQL database but I just can't get it to work: PHP Code:
I know what the password is (I just blanked it out above) so that's not an issue. Do I need to include a user name somewhere though? Any thoughts would be greatly appreciated. When I upload the page containing this code to my site it simply displays a blank page, if I take this section of code out everything is ok and I get the results I'm expecting. Here's the page without the PHP included. http://www.catsworthpcs.co.uk/maps/example.htm |
Re: PHP/SQL Help Please
Where you have [My Database] that should be the hostname that runs your MySql server. Something like mysql.i-websolutions.co.uk or whatever.
The user name is normally your account user name, rather than anything to do with the DB. In the mysql_select_db bit, you should use "catswor_maps" which appears to be the name of your DB? Or is that a table inside your DB? |
Re: PHP/SQL Help Please
Any idea where I need to include the username?
__________________ I just tried replacing [My Database] with the URL for my site and got no joy, I'm assuming it's trickier than that. Anybody successfully connecting to an I-Web MySql database got any idea what the path needs to be? |
Re: PHP/SQL Help Please
Quote:
What is the url you are using? If you are running the php on the box itself then you can just use localhost as shown below: $username = "name"; $password = "password"; $hostname = "localhost"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to mysql"); The username & password is the username & password for the mysql database. I've never used I-Web so I can only assume that there must be just one username that is global to your account. It might be worthwhile checking their website as you might need to specify a port to connect on. |
Re: PHP/SQL Help Please
The format of mysql_connect() is this ;
PHP Code:
Edit, oh well, beaten by half a dozen ....... :cool: |
Re: PHP/SQL Help Please
I think I'm being incredibly dense here :dunce:
It doesn't seem to want to work. I've substituted localhost, my user name, and my password and I still get a blank page. I've uploaded the code as I have it at the moment (including username and password. If you try to load the link above now you should just see the blank page (but you'll be able to see the source as well). Maybe someone can spot what I'm doing wrong? |
Re: PHP/SQL Help Please
Quote:
|
Re: PHP/SQL Help Please
That's what I thought.....
It's definitely running PHP though..... |
Re: PHP/SQL Help Please
Which server is the mysql database stored on and which server is running the HTML & the PHP?
__________________ Quote:
|
Re: PHP/SQL Help Please
Quote:
Ummm..... Other than the URL for the site and the fact that MyPHP Admin lists it as localhost (as said above) I'm not sure what other informtion I can give..... The HTML and the PHP are running from the public_html/maps folder of my webspace which is where the rest of the site pages sit. Quote:
|
Re: PHP/SQL Help Please
Quote:
|
Re: PHP/SQL Help Please
I think the server is unlikely to execute the php because you have used a .htm file extension - which it will simply serve up as a static html page.
|
Re: PHP/SQL Help Please
OK, can we clarify that the html & php you are running is on the same server that the mysql database is running on.
If it is then Paul M is right. |
Re: PHP/SQL Help Please
Quote:
It seems to be running the PHP now, if you check out: http://www.catsworthpcs.co.uk/maps/example.php You will see the result :( All I get now is a little grey // towards the bottom of the page. Here's the complete HTML: PHP Code:
|
Re: PHP/SQL Help Please
Quote:
Can\'t use dbmapserver : Access denied for user 'catswor_catswort'@'localhost' to database 'catswor_catswort' Looks like the username & password are incorrect. Either the db does not exist or it has additional authentication. I know in mysql you can add authentication right down to field level. |
Re: PHP/SQL Help Please
Ok, the username and password are correct.....
What error message are you getting now? I only ask that because I've made a change, it's still not working, and I'm not getting any error messages - I wasn't even getting the one that you were getting :( |
Re: PHP/SQL Help Please
Can't use database : Access denied for user 'catswor_catswort'@'localhost' to database 'catswor_maps'
|
Re: PHP/SQL Help Please
Ok, I've deleted that user and added a new one, then changed the user name and password in the PHP so that they match the new account created.
Still not working and still getting no error messages..... Is there any chance that there's something not set up quite right somewhere that I don't have access to on the site? |
Re: PHP/SQL Help Please
In mysql you will need to give users rights to access certain databases and tables. You can assign the select/update/delete rights for each user for a database & table. I don't know how it works with your provider as I do it from either a linux prompt or webmin.
|
Re: PHP/SQL Help Please
Ok, I think I'm getting somewehere.
Hadn't realised that you have to explicitly grant the user access to each database..... Done that now and I-Web's admin panel actually supplies the connection strings. The PHP now appears to be connecting to the database ok but I still get a blank page. I am now seeing an error message in the source for the page though: Quote:
|
Re: PHP/SQL Help Please
I would suggest that there is a problem with your query section of the code. From the paste of the code you have:
$result = mysql_query("SELECT * FROM 'memberlocations'",$link); If the memberlocations table exists then you do not need to put quotes around it: $result = mysql_query("SELECT * FROM memberlocations",$link); |
Re: PHP/SQL Help Please
:woot:
It's Working :D Thanks for all the help guys, really appreciate it :tu: It'll 404 at the moment though because I'm fiddling, give me a moment and I'll show you the result :) __________________ Ok, it's working now..... Click the balloon ;) It's the start of a little project that I've been wanting to have a go at for a while :) Thanks again for all the help :tu: |
Re: PHP/SQL Help Please
Quote:
|
Re: PHP/SQL Help Please
Quote:
The mysql_select_db() function actually does a "use <database>" command. The mysql_connect() function does establish the connection in the first place. You can probably test this by using this code: PHP Code:
|
| All times are GMT. The time now is 13:16. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum