• We just launched and are currently in beta. Join us as we build and grow the community.

PHP - Populate List With MySQLi

iCrackAccs

Tank Commander
I Rep
0
0
0
Rep
0
I Vouches
0
0
0
Vouches
0
Posts
89
Likes
48
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial we will create a Populate List With MySQLi using PHP. This code will display MySQLi data as a HTML list. The code use MySQLi SELECT query that will display the MySQLi row as a html list using mysqli_fetch_array(). This a user-friendly program feel free to modify and use it to your system.

We will be using PHP as a scripting language that interepret in the webserver such as xamp, wamp, etc. It is widely use by modern website application to handle and protect user confidential information.

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

And this is the link for the jquery that i used in this tutorial https://jquery.com/.

Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating Database

Open your database web server then create a database name in it db_list, after that click Import then locate the database file inside the folder of the application then click ok.
2019-11-15_23_29_06-localhost_127.0.0.1_db_list_phpmyadmin_4.8.3.png

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.
  1. <?php
  2. $conn

    =

    mysqli_connect

    (

    "localhost"

    ,

    "root"

    ,

    ""

    ,

    "db_list"

    )

    ;

  3. if

    (

    !

    $conn

    )

    {
  4. die

    (

    "Error: Failed to connect to database!"

    )

    ;
  5. }
  6. ?>

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" />
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
  6. </head>
  7. <body>
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  11. <div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">PHP - Populate List With MySQLi</h3>
  16. <hr style="border-top:1px dotted #ccc;">
  17. <div class="col-md-3">
  18. <form method="POST" action="add.php">
  19. <div class="form-group">
  20. <label>Enter a movie title</label>
  21. <input type="text" name="movie" class="form-control" required="required"/>
  22. </div>
  23. <center><button class="btn btn-primary" name="add">Add</button></center>
  24. </form>
  25. </div>
  26. <div class="col-md-9">
  27. <h2>MY MOVIE LIST <?php

    echo

    date

    (

    "Y"

    )

    ?>

    </h2>
  28. <ul>
  29. <?php
  30. require

    'conn.php'

    ;

  31. $query

    =

    mysqli_query

    (

    $conn

    ,

    "SELECT * FROM `movie`"

    )

    or die

    (

    mysqli_error

    (

    )

    )

    ;
  32. while

    (

    $fetch

    =

    mysqli_fetch_array

    (

    $query

    )

    )

    {
  33. echo

    "<li>"

    .

    $fetch

    [

    'movie_title'

    ]

    .

    "</li>"

    ;
  34. }
  35. ?>
  36. </ul>
  37. </div>
  38. </div>
  39. </body>
  40. </html>

Creating the Main Function

This code contains the main function of the application. This code will display the MySQLi data as a list when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as add.php
  1. <?php
  2. require_once

    'conn.php'

    ;

  3. if

    (

    ISSET

    (

    $_POST

    [

    'add'

    ]

    )

    )

    {
  4. $movie

    =

    $_POST

    [

    'movie'

    ]

    ;

  5. mysqli_query

    (

    $conn

    ,

    "INSERT INTO `movie` VALUES('', '$movie

    ')"

    )

    or die

    (

    mysqli_error

    (

    )

    )

    ;

  6. header

    (

    'location: index.php'

    )

    ;
  7. }
  8. ?>

There you have it we successfully created Populate List With MySQLi using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

450,053

322,753

322,762

Top