0

i got this code

if($_GET['action'] == 'test')
        {

            $query = "SELECT * FROM users WHERE user_id = {$_GET['id']}";
            $result = @mysqli_query($dbc, $query) or die('Query failed: ' . mysqli_error($dbc));


        }

And now i want to output a text like Username: Martijn (That's the user_name from ID 1) Reg date: 01/01/2015

But i can't get that working. I checked many stackoverflow questions but couldnt find it. Here you can see the website: http://admincontrol.martijnmelchers.nl/show_profile.php?action=test&id=1

4
  • Step 1, remove the error suppressing @ in @mysqli_query. Commented Jan 1, 2015 at 18:32
  • So $result = mysqli_query($dbc, $query) or die('Query failed: ' . mysqli_error($dbc)); Commented Jan 1, 2015 at 18:33
  • Your page says undefined variable row. Where is your while() code? Commented Jan 1, 2015 at 18:36
  • I don't have a while() code... Commented Jan 1, 2015 at 18:37

2 Answers 2

2

You don't need that error suppressiong there

This is usually in the third page in PHP-MySQL tutorials.

You have to add to your code, after the $result... line:

while($row  = mysqli_fetch_assoc($result))
{

 echo "<p> Username" . $row['user_name'] . " - Reg Date" . $row['reg_date'] . " .</p>";

}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very munch! I'll make it the answer when i can :)
1

You can use the mysqli_fetch_array function for this.

if($_GET['action'] == 'test')
{
        $query = "SELECT * FROM users WHERE user_id = {$_GET['id']}";
        $result = @mysqli_query($dbc, $query) or die('Query failed: ' . mysqli_error($dbc));
        $row = mysqli_fetch_array($result, MYSQLI_ASSOC); 
}
echo $row["Username"];

You'd have to replace Username with whatever your field name is in the database.

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.