Im trying to create a dynamic web page in php and mysql. I have the below code on the profile.php page. The issue im having is on the "while" line im not sure how i would go about getting the information from the DB. I want to display details like email, country First name, etc. Any help appreciated. Thanks in advance! CODE:
$userid = (isset($_GET['id']) ? $_GET['id'] : NULL);
if ($userid) {
$userinfo = $DB->query_first("SELECT * FROM `users` WHERE `id` = '$userid'");
print_r($userinfo);
}
//{
while($row = sql_fetch_assoc($DB)){
echo'<div class="container">
<div class="jumbotron" align="block">';
echo $row['first_name'];
echo $row['last_name'];
echo $row['country'];
echo $row['username'];
echo'</div>';
echo'</div>';
}
Try by using this
<?php
$userid = (isset($_GET['id']) ? $_GET['id'] : NULL);
if ($userid) {
$userinfo = $DB->query_first("SELECT * FROM `users` WHERE `id` = '$userid'");
print_r($userinfo);
?>
<table>
<tr>
<td>First Name</td>
<td><?=$userinfo['first_name']?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?=$userinfo['last_name']?></td>
</tr>
............
............
</table>
<?php } ?>
do not use null use a empty string "" that is what you want sql well do nothing with an empty string it is just white space, enough about sql injection attacks wtf ever topic i enter. actually make it equal to wither where userid='$userid' or "". there is only one row so the while statement is redundant just row = mysql_fetch_array.
You can try something like this:
<?php
$userid = (isset($_GET['id']) ? $_GET['id'] : NULL);
if ($userid) {
$userinfo = $DB->query_first("SELECT * FROM `users` WHERE `id` = '$userid'");
print_r($userinfo);
echo'
<div class="container">
<div class="jumbotron" align="block">
'.$userinfo['first_name'].' <br>
'.$userinfo['last_name'].' <br>
'.$userinfo['country'].' <br>
'.$userinfo['username'].' <br>
</div>
</div>';
?>