Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:08:19+00:00 2026-06-15T21:08:19+00:00

Im trying to echo out two things from database, why wont this work? and

  • 0

Im trying to echo out two things from database, why wont this work? and how do i get this to work. Im just learning php so if this is a realy dumb question im sorry.

$result = mysql_query("SELECT user_id, team FROM users WHERE username = '$username'");
while($row = mysql_fetch_array($result))
$user_id = $row['user_id'];
$team = $row['team'];

echo = $user_id;
echo = $team;`

I’m thankful for any help you can provide!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:08:21+00:00Added an answer on June 15, 2026 at 9:08 pm

    As tpaksu already mentioned, you need brackets around the statements you want your loop to execute.

    Second, the correct format for echo is

    echo $user_id;
    

    And two other, rather fundamental remarks

    • the mysql calls are deprecated which means that they have been replaced by newer alternatives (specifically either mysqli or better still PDO). Don’t waste time learning howto use the mysql* family of calls, switch to mysqli or preferably PDO now.
    • an sql statement like "SELECT user_id, team FROM users WHERE username = '$username'"); where a variable is included as-is in an SQL statement is a huge risk for SQL injection. You could waste precious time devising all kinds of clever schemes to sanitize variables before inclusion, or you could learn to do it the only right way, that is, by using prepared statements. It may be less intuitive at first sight but you’ll quickly get used toit.

    This will transform your code into something like this:

    <?php
      $stmt = $dbh->prepare("SELECT user_id, team FROM users WHERE username = ?");
      if ($stmt->execute(array($username))) {
        while ($row = $stmt->fetch()) {
          $user_id = $row['user_id'];
          $team = $row['team'];
    
          echo $user_id;
          echo $team;
        }
      }
    ?>
    

    which is injection proof and uses up to date technology. As a bonus side effect, it will be a lot easier to adapt to other brands of databases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to figure out how to output my php to echo for my
i am trying to echo a html files contents from a php script. Quite
Trying to work out distance between two points (lat & lng) I have an
I am trying to list out all records from a database that have not
I am trying to get a percentage of a php variable from another, for
I'm trying to compare two dates in PHP and figure out how many days
I'm trying to query a single result from two tables in my database. Here
I'm trying to echo out all variables of two arrays with a single foreach
I'm trying to echo the XML content at this URL but I'm having difficulty.
I am trying to echo a result from xml into my html code form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.