Page 1 of 2

annoying syntax problem (i think)

Posted: Tue Dec 16, 2003 8:34 am
by malcolmboston
heres the code
basically it wasnt working, so i thought id print out the query it is trying to do, it gives out this:
SELECT password from ".$tablename." WHERE username = ''
not sure why it is doing that at all, put thats all i can think of this problem and i have no idea how to fix it does anyone have any ideas?

Code: Select all

<?php 
// database variables for connections 
$host = "localhost"; 
$user = "malcolmboston"; 
$password = "xxxxx"; 
$DBname = "TDN"; 
$tablename = "login_DB"; 
//connection variables completeed 

// establishing connections 
$link = mysql_connect ($host, $user, $password); 
//connection established 

//the query defined 
$query = "SELECT password from ".$tablename." WHERE username = '".$_SESSION['username']."'";

//the result 
$result =mysql_db_query($DBname, $query, $link); 
$line = mysql_fetch_array($query, MYSQL_ASSOC); 

echo $result;
echo $line['username'];
?>
the session variable is getting set because i can echo it on any page using

Code: Select all

print $_SESSION['username'];
does anyone have any insight into teh problem?

Posted: Tue Dec 16, 2003 8:39 am
by JayBird
are you 100% sure that when you echoed the query you got

Code: Select all

SELECT password from ".$tablename." WHERE username = ''
Can't see why is would parse one variable and not the other, your code is technically correct, i ran it on my server and works fine.

Mark

Posted: Tue Dec 16, 2003 8:42 am
by malcolmboston
exactly!

neither can i

not sure if the end digits where '' (2 commas) or "(quotation mark) but yeah thats what it said, absolutely baffling

and im gonna stress it again the variable is definitely there!!! i echo it on every page and it gives me back a value of malcolmboston, test, admin or whoever i decide to login as

this is really doing my head in

Posted: Tue Dec 16, 2003 8:47 am
by malcolmboston
btw i use

foxserv3.o php/mysql/apache model
on a windows 2000 pro box

Posted: Tue Dec 16, 2003 8:47 am
by JayBird
what if you just do

Code: Select all

echo $tablename;
Does it print login_DB to the screen?

Mark

Posted: Tue Dec 16, 2003 8:48 am
by twigletmac
Is that the whole page? Do you do a session_start() on that page? Is this really echoed as shown ' ".$tablename." '? Cause that would be really weird.

BTW, [php_man]mysql_db_query[/php_man]() is a deprecated function.

Mac

Posted: Tue Dec 16, 2003 8:50 am
by malcolmboston
using the table variable works perfectly but i changed it to login_DB when i was debugging, it worked exactly the same either way

and yes a session start is called because it can display my session var seperately on the page when i echo it

i also have lots of other coding written that
echos session name etc

its all there, thats what i dont understand

Posted: Tue Dec 16, 2003 9:02 am
by malcolmboston
no1 got any ideas about a possible cause to this problem?

ive viewed it in zend and DW both have problems displaying correct result, zend says its correct but still wont give me the result and tells me nothing about the error

Posted: Tue Dec 16, 2003 9:07 am
by JayBird
so can you echo $tablename or not?

If you can, and judging by previous problems you have had, you PHP installation seems to be f*cked.

Mark

Posted: Tue Dec 16, 2003 9:11 am
by malcolmboston
yep

Posted: Tue Dec 16, 2003 9:17 am
by malcolmboston
ive just had an idea but cannot test it until i get home

if at the beginning of the page i put something to the effect of

Code: Select all

?php
$_SESSION['username'] = $value;
and then in the query put

Code: Select all

$query = "SELECT password from ".$tablename." WHERE username = ".$value."";
then would that work?

because that would make it alot simpler query-wise and turn it more like $tablename which works

possibly pointless as it is doing the same thing but simplifies the query so it may be able to read it

Posted: Tue Dec 16, 2003 9:22 am
by JayBird
shouldn't make any difference whatsoever.

I would be worried that you can echo $tablename in one place, but can't concatenate in another.

That is just weird!

As i said before, i think your PHP installation may well be f*cked

Mark

Posted: Tue Dec 16, 2003 9:23 am
by malcolmboston
no it cant be

because i can echo it anywhere, but the MYSQL query wont do it

the var is there, but mysql wont include it in its query

Posted: Tue Dec 16, 2003 9:24 am
by JayBird
it has nothing to do with MySQL, it is still PHP where it can't include it.

Mark

Posted: Tue Dec 16, 2003 9:26 am
by malcolmboston
well, i cannot see how it is a PHP error when it is using it in other circumstance

when i create the variable it there because i can retrieve it anywhere on the site!!
(this is how i get hello %username% to work always and without problems)

its the query that is going wrong