I have been working on this thing for 2 weeks, and I continue to get errors. I was getting errors with my line 2 require code, but I think I fixed that, now only to get a parsing code: (Parse error: syntax error, unexpected '(' in /home/massage/public_html/phpsqlsearch_genxml.php on line 14)
I have the reset of the code I will try to attach it, please help me with this, I am somewhat okay with php and phpmyadmin, but not very strong. So this could be a simple fix. I am trying to build the map at http://code.google.com/support/bin/answer.py?answer=87134&topic=11364&ctx=sibling just FYI,
Getting a parsing error with Geocoding Business Locator
Looks like line 14 should be:
$connection=[color=red]mysql_connect[/color](localhost, $username, $password);
PS: You could have just pasted that code into your post within [noparse]
...
[/noparse] tags for us to read without having to download an attachment.
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/massage/public_html/phpsqlsearch_genxml.php on line 14
Not connected :
I am getting denied now, but it looks like progress is being made! Thank you, any ideas from here?
Thanks NogDog, that worked, now if I can get it to quick denying me as nobody as localhost?
Do $username and $password have values set for them? (Also, 'localhost' should be quoted.)
Upon further review: what does the "Connections/mysql.php" file do that is require()'ed at the start of the script? (Maybe line 14 isn't even needed?)
Okay, my knowledge of php/sql is medium so bear with me. per the tutorial I am going through I setup mysql.php with username and password to login to my database. I have to do that to pull the data for the locations to geocode them on the fly. ( I will quote localhost ) I would be more than happy to not have line 14 believe me, but I think I have to login to phpmyadmin. I am building a business locator utilizing the google maps api along with my locations in sql.
Why is it saying nobody@localhost, and using password NO? That just doesn't make sense to me
This is the file connections/mysql.php
<?php
FileName=""
Type="MYSQL"
HTTP="true"
$hostname_mysql = "localhost";
$database_mysql = "massage_directory";
$username_mysql = "*****";
$password_mysql = "*****";
$mysql = mysql_pconnect($hostname_mysql, $username_mysql, $password_mysql) or trigger_error(mysql_error(),E_USER_ERROR);
?>
I have to run home, I don't guess you will be here in an hour? if not, I will follow whatever you say, and hopefully run into you later.
jschrader;10907576 wrote:This is the file connections/mysql.php
<?phpFileName=""
Type="MYSQL"
HTTP="true"
$hostname_mysql = "localhost";
$database_mysql = "massage_directory";
$username_mysql = "*****";
$password_mysql = "*****";
$mysql = mysql_pconnect($hostname_mysql, $username_mysql, $password_mysql) or trigger_error(mysql_error(),E_USER_ERROR);
?>
Note that this include file does a mysql_pconnect() at the end. Personally, I would change that to mysql_connect() (i.e., without the "p") unless you really know what you're doing with persistent connections.
Then you can just use that connection within the main script, using the variable $mysql instead of any place you use $connection (or else change the variable to $connection in the include file, whichever makes more sense for you to do).
I know how stupid this sounds, but why do I have to first do a file require (connections/mysql) and then do a variable $connection="mysql_blah_blah_blah? The only thing stopping me from this script is this !@#$% connection.
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/massage/public_html/phpsqlsearch_genxml.php on line 14
Not connected :
Can you please tell me what else would cause this? I changed the variable to $mysql changed the connection off of persistant connections, what else? Why is it saying user nobody @ localhost?
When you require() (or include()) a file, it's as though the contents of the file were actually in the main script at the point you require it. So you could do:
Change the connections/mysql.php file to:
<?php
# FileName=""
# Type="MYSQL"
# HTTP="true"
$hostname_mysql = "localhost";
$database_mysql = "massage_directory";
$username_mysql = "********"; // don't forget to change to actual DB user name
$password_mysql = "********"; // don't forget to change to actual DB user password
// change variable name to "$connection" and use regular connection:
$connection = mysql_connect($hostname_mysql, $username_mysql, $password_mysql) or trigger_error(mysql_error(),E_USER_ERROR);
?>
Change your main script to:
<?php
require("Connections/mysql.php");
// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// got rid of connection stuff since already done in the required file above
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Search the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
?>