Click to See Complete Forum and Search --> : mysql_fetch


dudhi
07-03-2007, 11:42 AM
This is my code right now.


mysql_select_db($dbname);
echo "<br>";
$name = $_POST["name"];
$password = $_POST["pass"];
$query = " select * from `XXX`";

print_r($query);
echo "<br>";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
if( $row["UserName"] == $name)
{
echo $row["Password"];
echo "<br>";
}




What I have been trying to do is run this mysql comman
" Select `password` from xxx where username = $_POST["name"] "
But when I try to use while ($row = mysql_fetch_assoc($result)) command
with it, never works for me so had to modify mysql command and use the if loop after that. Was wondering if there is any other fetch command I can use.

Thanks to anyone looking into this.

temp.user123
07-03-2007, 11:55 AM
This is missing single quotes around the value:

"Select `password` from xxx where username = $_POST["name"] "
Try this:

"Select `password` from xxx where username = '{$_POST['name']}';"

dudhi
07-03-2007, 12:08 PM
That part works fine, I have declared a variable $name before that, I was just using _POST just to make it easier for people.

mysql_fetch is where I am having trouble with(Gives me an error as well.) when I try to use the mysql command
Select `password` from xxx where username = $_POST["name"]

temp.user123
07-03-2007, 12:14 PM
So what is the error message(s)?

dudhi
07-03-2007, 12:22 PM
mysql_fetch_array(): supplied argument is not a valid MySQL result resource

temp.user123
07-03-2007, 12:33 PM
No error from this statement?

$result = mysql_query($query);

dudhi
07-03-2007, 12:42 PM
nope, no error from that one. and the other error pops up only when I use the other select statement.
so only when using select a field like
select `password` from XXX where "blah blah blah"

temp.user123
07-03-2007, 12:50 PM
How about eliminating that space before the word SELECT?

Is `password` a valid name for one of the columns in your table?

...and what does this actually output?

print_r($query);
echo "<br>";