In a message dated 12/27/02 8:26:10 AM Pacific Standard
Time, [EMAIL PROTECTED] writes:

> I am trying to retrieve a password and print it using
a query which is
>  written as followos
>  $query2 = "select passwd from user where username =
>  $result = mysql_result($query2);
>  echo "<center>Old Password was $result </center>";
>  am I using mysql_result right or is there another
function to print this
>  password taking in consideration that it just prints
"Old Password was" and

Actually, it would go like this:

$query2 = "select passwd from user where username =
$result = mysql_query($query2);
$row = mysql_fetch_array($result);
echo "<center>Old Password was $passwd </center>";

There are other ways. And shorter ones for this
particular task. But this is kind of a general purpose
set of statements that will usually do what you need. 

The mysql_query function sends the SQL query to the
database and puts the data returned into a temporary
table. mysql_fetch_array gets a row of data from the
temporary table and puts it into an array that you can
then process. The extract function creates separate
variables from the array. 

If you are getting more than one row from the database,
you can use the extract statement in a loop and process
each row.


Janet Valade
Author, PHP & MySQL for Dummies

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to