Page 1 of 1

question

Posted: Tue Nov 22, 2011 8:46 pm
by jackson_1
Hi everybody,

I couldn't print a column of database in the code below. Please help me.

Code: Select all

$query = "SELECT UserId, FirstName, LastName, UserName, Password FROM User WHERE User.UserName =
'".$_POST["username"]."' AND User.Password = '".$_POST["password"]."'";

$result = mysql_query($query) or die('Query failed');

if (mysql_fetch_row($result)){
$cnt = mysql_num_rows($result);
$row =  mysql_fetch_array($result);

while($row = mysql_fetch_array( $result )) {
                
echo $row['FirstName'];  [b]<------------ This doesn't work[/b]
        } 
}

Re: question

Posted: Tue Nov 22, 2011 10:36 pm
by Gopesh
Hi,Any error messages got? Pls post the full code including the connection satements.

Re: question

Posted: Wed Nov 23, 2011 12:08 am
by JeFFb68CAM
Either change

Code: Select all

while($row = mysql_fetch_array( $result )) {[c
to

Code: Select all

while($row = mysql_fetch_array( $result, MYSQL_ASSOC )) {
or to

Code: Select all

while($row = mysql_fetch_assoc( $result )) {

Re: question

Posted: Wed Nov 23, 2011 12:12 am
by JeFFb68CAM
I just noticed you have a lot of extras there. Get rid of it, try this:

Code: Select all

$query = "SELECT UserId, FirstName, LastName, UserName, Password FROM User WHERE UserName =
'".$_POST["username"]."' AND Password = '".$_POST["password"]."'";

$result = mysql_query($query) or die('Query failed');

if (mysql_num_rows($result) == 1){
    $row = mysql_fetch_assoc($result);
    echo $row['FirstName'];
}