How to display info from a MySQL database using PHP?

Discussion in 'PHP' started by Ipodman79, Jan 28, 2014.

  1. #1
    I want to display values from a MySQL database using PHP.

    I already have it connected to the database via an external php file.

    I want it so that it displays the info like,

    
    <p>
            Message: <?php echo *value from database*;?>
    </p>
    
    PHP:
    How do I do this?
     
    Ipodman79, Jan 28, 2014 IP
  2. suvidha.writer

    suvidha.writer Active Member

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    you have to use mysql_query , search on google you can get thousands of example for mysql_query
     
    suvidha.writer, Jan 28, 2014 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    No, seriously. You do NOT have to use mysql_query. In fact, for all that is holy, you should NOT use mysql_query. It's outdated, it will (hopefully soon) be defunct, and should not, in any way, be used.
    Search for mysqli_ or PDO and use either of those to connect to your database.
    Here's a few links to get you started:
    http://www.dreamincode.net/forums/topic/54239-introduction-to-mysqli-and-prepared-statements/
    http://codular.com/php-mysqli
    http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

    The first two are for mysqli, the third one is for PDO
     
    PoPSiCLe, Jan 28, 2014 IP