On Oct 11, 2008, at 1:08 PM, chellieclk wrote:

> Hi Everyone. I am having a bit of a mysterious error that I cannot  
> find a solution to.
> I can manually assign a value to $uid and everything works. With a  
> var though, I keep
> getting an error about mysql _query not having a valid resource.
>
> I cannot get variables to work in my sql statements; I have tried  
> quotes, brackets, braces,
> etc. Any idears would be greatly appreaciated.
>
> <?PHP
>
> //var passed from calling function;
> $uid;
>
> //test to see if value is indeed making it over from calling function
> echo $uid;
>
> //mysql query
> $sql = "SELECT u_name FROM members WHERE u_name = {$uid}";
> $result = mysql_query($sql);
>
> while ($row = mysql_fetch_assoc($result) {
>
> //test to try and figure out what is going on
> echo $row['u_name'];
>
> //tenery statement to evaluate and reassign value to $uid.
> //this statement should live inside the while loop!
>
> $uid = (!$result || $result == NULL || $result == '0') ? NULL :  
> $row['u_name'];
> }
> ?>


This code just doesn't make any sense to me.    What is it you're  
trying to do?  Is this supposed to be a function?  If so, where's the  
function declaration?  Or is this file being "included" wherever you  
need it?  What are you trying to do with the first statement, it's  
just the name of the variable...

Your SQL statement should be concatenated like so:

$sql = "SELECT u_name FROM members WHERE u_name = " . $uid;

Then maybe you can echo the statement and see what's actually getting  
called (You can then put it into the MYSQL manually and see if it's  
working).

Also, your while statement is missing a closing parenthesis, so it's a  
syntax error.

Lastly, why are you checking the value of result inside the while?   
(If you actually get inside the while statement, $result will have  
some sort of value.) and then you just set the value of $uid to itself  
(because from your SQL, u_name must equal uid...)

Any clarification on what this is supposed to do might yield you some  
better help.



-D. Israel
[EMAIL PROTECTED]
http://www.customcodebydan.com
AIM: JudoDanIzz



[Non-text portions of this message have been removed]

Reply via email to