How to echo database fields with PHP?

Nemanja

Premium Member
Joined
Nov 23, 2012
Messages
293
Points
28
So, I'm learning basics of PHP and Mysql and I am trying to print my database data to a PHP page. I have a table username, email and URL fields. I'm trying to select this table and echo field values but the result returned is a blank page. What does this mean?
Could you please post some sample of showing data from a database by echo them using PHP?

Thanks in advance.
 

Ruesnam

Member
Joined
Mar 6, 2017
Messages
59
Points
8
If I got your point, then let me give you an example.
Let's say you have a table called 'user', and you want to print a field called 'username'

PHP:
<?php
     try{
        $database = new PDO($host, $user, $password);//database credentials
    }
   catch(Exception $e){
        die('Failure : '.$e->getMessage());
   }
   $request = $database->prepare('SELECT * FROM user ');
   $request->execute();
   $result = $request->fetch();
   if($result){
     echo $result['username']; 
  }
  
?>
Hope it helped :)
 

Mike001

New member
Joined
Apr 27, 2016
Messages
578
Points
0
Ruesnam,

I know that you mean well but if Nemanja does not understand the structural layout of PHP, there is very little chance that he will understand what you have displayed in classes.

My guess is, he is trying to fill a variable with multiple fields. That happens a lot to new programmers that do not have a good understanding of variables vs. arrays.

Nemanja if you add your code I can help you displaying the data. Or if you are really motivated you can watch a bunch of free videos on my website, under the PHP section that will explain exactly what you are trying to do.

Just a thought.
 
Older threads
Replies
3
Views
1,472
Replies
4
Views
2,612
Replies
13
Views
4,474
Newer threads
Replies
7
Views
2,988
Replies
4
Views
3,827
Replies
3
Views
1,605
Latest threads
Replies
2
Views
126
Replies
1
Views
189
Replies
6
Views
431
Replies
11
Views
546
Replies
2
Views
238
Recommended threads
Replies
12
Views
7,175
Replies
5
Views
2,663
Replies
1
Views
2,184

Latest postsNew threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top