Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Cheap ink deal!

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion
Register FAQ Community Calendar

PHP/SQL Help Please
Reply
 
Thread Tools
Old 30-07-2005, 23:28   #1
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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:
<?php
$link 
= mysql_connect("[My Database]", "dbmapserver", "[Password]")
or die(
"Could not connect: " . mysql_error());
mysql_selectdb("dbmapserver",$link) or die ("Can\'t use dbmapserver : " . mysql_error());

$result = mysql_query("SELECT * FROM 'memberlocations'",$link);
if (!
$result)
{
echo 
"no results ";
}
while(
$row = mysql_fetch_array($result))
{
echo 
"var point = new GPoint(" . $row['lon'] . "," . $row['lat'] . ");\n";
echo 
"var marker = createMarker(point, '" . $row['desc'] . "');\n";
echo 
"map.addOverlay(marker);\n";
echo 
"\n";
}

mysql_close($link);
?>
Where it says "[My Database]" I need to put in the name of my database (Duh!), the database is hosted on my I-Web hosting account as a MySQL database and is called "catswor_maps" - what should I put in as the name of the database? Do I need to include the full path of the site? Do I just put in the database name?

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
Raistlin is offline   Reply With Quote
Advertisement
Old 30-07-2005, 23:35   #2
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
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?
punky is offline   Reply With Quote
Old 30-07-2005, 23:39   #3
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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?
Raistlin is offline   Reply With Quote
Old 30-07-2005, 23:43   #4
iron25
Inactive
 
Join Date: Aug 2003
Location: nowhere
Posts: 718
iron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful one
Re: PHP/SQL Help Please

Quote:
Originally Posted by Raistlin
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?

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.
iron25 is offline   Reply With Quote
Old 30-07-2005, 23:44   #5
Paul
Dr Pepper Addict
Cable Forum Admin
 
Paul's Avatar
 
Join Date: Oct 2003
Location: Nottingham
Age: 63
Services: Zen & YouFibre FTTP, Sky Q TV, Sky Mobile, Flextel SIP
Posts: 31,385
Paul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered stars
Paul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered stars
Re: PHP/SQL Help Please

The format of mysql_connect() is this ;

PHP Code:
mysql_connect('server', 'user', 'password') 
You then use the mysql_select_db() statement to connect to your database. If the php is running on the same server as mysql then the server will be 'localhost'.

Edit, oh well, beaten by half a dozen .......
__________________

Baby, I was born this way.
Paul is offline   Reply With Quote
Old 30-07-2005, 23:56   #6
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: PHP/SQL Help Please

I think I'm being incredibly dense here

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?
Raistlin is offline   Reply With Quote
Old 31-07-2005, 00:04   #7
iron25
Inactive
 
Join Date: Aug 2003
Location: nowhere
Posts: 718
iron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful one
Re: PHP/SQL Help Please

Quote:
Originally Posted by Raistlin
I think I'm being incredibly dense here

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?
If it is running PHP then we should not be able to view the PHP code in 'View Source' only the results
iron25 is offline   Reply With Quote
Old 31-07-2005, 00:05   #8
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: PHP/SQL Help Please

That's what I thought.....

It's definitely running PHP though.....
Raistlin is offline   Reply With Quote
Old 31-07-2005, 00:06   #9
iron25
Inactive
 
Join Date: Aug 2003
Location: nowhere
Posts: 718
iron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful one
Re: PHP/SQL Help Please

Which server is the mysql database stored on and which server is running the HTML & the PHP?
__________________

Quote:
Originally Posted by Raistlin
That's what I thought.....

It's definitely running PHP though.....
It can't be
iron25 is offline   Reply With Quote
Old 31-07-2005, 00:10   #10
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: PHP/SQL Help Please

Quote:
Originally Posted by iron25
Which server is the mysql database stored on and which server is running the HTML & the PHP?
It's on whatever server my website is set up on.....I'm sure that's not a lot of use though is it

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:
Originally Posted by iron25
Quote:
Originally Posted by Raistlin
That's what I thought.....

It's definitely running PHP though.....
It can't be
It says that it is on the main page of the Control Panel for the site.....maybe I'm reading it wrong (or I've got to set something else up).....
Raistlin is offline   Reply With Quote
Old 31-07-2005, 00:12   #11
Tezcatlipoca
Inactive
 
Tezcatlipoca's Avatar
 
Join Date: Jun 2003
Location: Cambridge
Posts: 16,760
Tezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny stars
Tezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny starsTezcatlipoca has a pair of shiny stars
Re: PHP/SQL Help Please

Quote:
Originally Posted by Raistlin
It says that it is on the main page of the Control Panel for the site.....maybe I'm reading it wrong (or I've got to set something else up).....
Have you created a User for the database? (I have one, same name as the database itself, used for my blog)
Tezcatlipoca is offline   Reply With Quote
Old 31-07-2005, 00:12   #12
Paul
Dr Pepper Addict
Cable Forum Admin
 
Paul's Avatar
 
Join Date: Oct 2003
Location: Nottingham
Age: 63
Services: Zen & YouFibre FTTP, Sky Q TV, Sky Mobile, Flextel SIP
Posts: 31,385
Paul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered stars
Paul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered starsPaul is seeing silvered stars
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.
__________________

Baby, I was born this way.
Paul is offline   Reply With Quote
Old 31-07-2005, 00:13   #13
iron25
Inactive
 
Join Date: Aug 2003
Location: nowhere
Posts: 718
iron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful one
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.
iron25 is offline   Reply With Quote
Old 31-07-2005, 00:18   #14
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: PHP/SQL Help Please

Quote:
Originally Posted by Paul M
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.
Well spotted

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:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAA_0Z8PeM-XgTpnTEQ2Eu_dhS9v8dKVB9YxxVRvDfddQklYutOPxSzQleklTrdQ1Oj9gVkdwpq6oq7uQ" type="text/javascript"></script>
  </head>
  <body>
    <div id="map" style="width: 500px; height: 400px"></div>
    <script type="text/javascript">
//<![CDATA[

var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(***), 12);

// Creates a marker whose info window displays the given number
function createMarker(point, number)
{
var marker = new GMarker(point);
// Show this markers index in the info window when it is clicked
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};
<?php
$link 
= mysql_connect('localhost', '***', '***')
or die(
"Could not connect: " . mysql_error());
mysql_selectdb('***',$link) or die ("Can\'t use dbmapserver : " . mysql_error());

$result = mysql_query("SELECT * FROM '***'",$link);
if (!
$result)
{
echo 
"no results ";
}
while(
$row = mysql_fetch_array($result))
{
echo 
"var point = new GPoint(" . $row['lon'] . "," . $row['lat'] . ");\n";
echo 
"var marker = createMarker(point, '" . $row['desc'] . "');\n";
echo 
"map.addOverlay(marker);\n";
echo 
"\n";
}

mysql_close($link);
?> 

//]]>
</script>

</body>
</html>
  </body>
</html>
Have I made another dumb mistake somewhere?
Raistlin is offline   Reply With Quote
Old 31-07-2005, 00:21   #15
iron25
Inactive
 
Join Date: Aug 2003
Location: nowhere
Posts: 718
iron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful oneiron25 is the helpful one
Re: PHP/SQL Help Please

Quote:
Originally Posted by Raistlin
Have I made another dumb mistake somewhere?
Yes

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.
iron25 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 17:19.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum