PHP help continued...

sax0n

New Member
Messages
11
Reaction score
0
Points
0
Right. I've been mulling this one around for a while and I have came up with this.
PHP:
<html>
<head>
<title> Main </title>
</head>
<body>
<h3> Test </h3>
<?php 
$dbhost = 'localhost';
$dbuser = 'sax0n';
$dbpass = 'password';

mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

mysql_select_db("sax0n_main") or die; 

$username = 'saxon';
$ui_query = mysql_query("SELECT * FROM user_info WHERE username = '$username' LIMIT 1");
$ui_table = mysql_fetch_assoc($ui_query);
echo $ui_table[level];
$co_long = $ui_table['co_ords_long']; 

$map_query = mysql_query("SELECT * FROM map WHERE 'co_ords_long' = '$co_long' AND 'co_ords_lat' = '$co_lat' LIMIT 1"); 
$map_table = mysql_fetch_assoc($map_query);
$player_location = $map_table[name];
echo $map_table[name];
echo $player_location ;
</body>
</html>

With the output...

Test
1

I dont get why level echos but name doesn't! :dunno:

Help is infinitley appreciated!
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
should
PHP:
echo $map_table[name];
be
PHP:
echo $map_table['name'];
?
 

mephis

New Member
Messages
39
Reaction score
0
Points
0
should
PHP:
echo $map_table[name];
be
PHP:
echo $map_table['name'];
?

not sure that the problem lies there (although it's a good point).

I think the problem is in the second SQL query:
Code:
$map_query = mysql_query("SELECT * FROM map WHERE 'co_ords_long' = '$co_long' AND 'co_ords_lat' = '$co_lat' LIMIT 1");
it should be:
Code:
$map_query = mysql_query("SELECT * FROM map WHERE co_ords_long='$co_long' AND co_ords_lat='$co_lat' LIMIT 1");
...no single quotes in the table field names. Try running that query on your database (say... using phpmyadmin or so) and see what it says...
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
what mephis said was right, but in your second query, you're calling $co_lat, but you haven't set the variable.
 
Last edited:

sax0n

New Member
Messages
11
Reaction score
0
Points
0
Yay! Thanks Mephis! That worked. :biggrin:

what mephis said was right, but in your second query, you're calling $co_lat, but you haven't set the variable.

I have but that bit got cut out when I was copy and pasting.
 
Top