Is it possible to connect Database to HTML?

  1. 3 months ago
    Edited 3 months ago by Kevin W

    Hi everyone,
    i have a question from my problem, is it possible to connect a PHP file which contain MySQL script into HTML file? if yes, does the connection really works? in example, i'm trying to send the form data from HTML into database by using PHP as a bridge for the two of it. from many of examples that i have search, there is almost no examples like the problem that i had, most of it recommends to use PHP file from scratch instead of HTML-PHP connection file.

    My code goes with something like this

    <?php
        $db = mysqli_connect('localhost','root',' ','kantor');
    ?>
    <html>
        <body>
              <?php
                    $query = "SELECT * FROM `form`;";
                    $result = mysqli_query($db, $query);
                    while($row = mysqli_fetch_assoc($result)) 
                   {
    
                    }
              ?>
        </body>
    </html>

    Sorry if it's sounds kind of silly, but i really confused about it because i prefer if i can do it by using HTML and PHP rather than going all PHP for both of the Front-end and Back-end. Thank you very much for reading and your time.

  2. Wayne G

    May 17 Pre-Release Testers, Xojo Pro New Zealand axisdirect.nz

    Hey @Kevin W welcome to the Xojo community - the friendliest on the Web. Your question seems to be not related to Xojo, so while you may get some friendly advice from here you aren't really in scope.

  3. Sorry if my question not kind of related to Xojo, i'm kind of starting in here too. anyway, thanks for the information!

  4. Tim H

    May 18 Pre-Release Testers Portland, OR USA

    Yes, you can combine php and html in a single file. It must have a php extension, though, not htm or html.

  5. I really don't like to see PHP and HTML mashed together, I much prefer to see a single page web app as a front end interacting with the back end using JSON.

or Sign Up to reply!