Beginner Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Beginner Question

Post by AliasBDI »

This may be stupid but I've never had to do it. So now that I do need it, I cannot figure it out.

I need to query the database for a particular record with WHERE. Then I need to take the particular fields (stated in the query) and turn them into constants to be used elsewhere in the page below.

Here is my code so far:

Code: Select all

<?php
$result = mysql_query("SELECT first_name, last_name, email_address, username, decrypted_password, dl, birth FROM users WHERE dl='16638868' AND birth='10-28-1978' ") or die (mysql_error());
if (!$result) &#123;
    print mysql_error()." ERROR - browse query failed.";
    exit();
&#125;
while ( $row = mysql_fetch_array($result) )
 &#123;    
echo ($row&#1111;"username"]);  
echo $row&#1111;"first_name"];
&#125;
?>
Now, as you can see I can only echo the field results. But I need them to be constants. I tried doing the basic "$username = echo ($row["username"])" but it did not work.

Any ideas?
Last edited by AliasBDI on Tue Oct 21, 2003 9:41 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Instead of

Code: Select all

$username = echo ($row["username"]);
try

Code: Select all

$username = $row['username'];
Mac
Last edited by twigletmac on Wed Oct 22, 2003 3:10 am, edited 1 time in total.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

thanks

Post by AliasBDI »

WORKED great!

Thanks.
Last edited by AliasBDI on Tue Oct 21, 2003 9:43 am, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$username = $row['username']; <-- you are missing the ;
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

THanks

Post by AliasBDI »

thanks markl999,

I noticed that and changed my post in an attempt to save anyone else from being bothered with it....thanks though.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

markl999 wrote:$username = $row['username']; <-- you are missing the ;
Copy and paste error, oops.

Mac
Post Reply