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!
As tpaksu already mentioned, you need brackets around the statements you want your loop to execute.
Second, the correct format for echo is
And two other, rather fundamental remarks
"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:
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.