1

I'm trying to display members from my database using PHP, however the last name goes in with the first name and I'm not quite sure why... Could anyone point me in the right direction?

<?php
$mysql_db_hostname = "localhost";
$mysql_db_user = "alex";
$mysql_db_password="";
$mysql_db_database="gym";

$con = mysql_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password) or die("Could not connect database");

mysql_select_db($mysql_db_database, $con) or die("Could not select database");

$query = mysql_query("select * from users WHERE Category='Member'");

echo "<table border=1>
<tr>
<th>Users ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>";

while($row =mysql_fetch_assoc($query))
{
echo "<tr>";
echo "<td>" . $row['user_id']."<br>" . "</td>";
echo "<td>" . $row['First_Name']."<br>" . "</td";
echo "<td>" . $row['Last_Name']."<br>" . "</td";
echo "</tr>";
}

echo "</table";
?>
3
  • You aren't closing the </td> tags Commented Mar 17, 2014 at 20:39
  • html error, look at the td's Commented Mar 17, 2014 at 20:40
  • As all the answers have indicated, the td tags are not closed. But make sure to notice your table tag as well. Commented Mar 17, 2014 at 20:46

3 Answers 3

3

You aren't closing the tags. Syntax highlighter would show the error.

while($row =mysql_fetch_assoc($query))
{
    echo "<tr>";
    echo "<td>" . $row['user_id']."<br>" . "</td>";
    echo "<td>" . $row['First_Name']."<br>" . "</td"; <-----------
    echo "<td>" . $row['Last_Name']."<br>" . "</td"; <------------
    echo "</tr>";
}
Sign up to request clarification or add additional context in comments.

Comments

0

You are not closing your <td> tags properly

echo "<td>" . $row['First_Name']."<br>" . "</td>";
                                             //^here
echo "<td>" . $row['Last_Name']."<br>" . "</td>";
                                             //^and here

So the output is all one cell with both variables printed inside

Comments

0

You forgot to close the td on your first name field.

Just change

</td

to

</td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.