• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

PHP - Limit Maximum Post Submit

wadeaw342

Endpoint Security Evaluator
W Rep
0
0
0
Rep
0
W Vouches
0
0
0
Vouches
0
Posts
75
Likes
87
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 900 XP
In this tutorial we will create a Limit Maximum Post Submit using PHP. This code can limit the submitted post when user reach the maximum entries. The code use MySQLi POST method to call a specific function that prompt a warning when you reach the maximum entry for your database using mysqli_num_rows() to track the number of rows available in the table. This a user-friendly program feel free to modify and use it to your system.

We will be using PHP as a scripting language and interpreter that is used primarily on any webserver including xamp, wamp, etc. It is being use to any famous websites because of modern approach as its today.

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 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_post_limit, after that click Import then locate the database file inside the folder of the application then click ok.
2019-08-13_00_29_33-localhost_127.0.0.1_db_post_limit_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_post_limit"

    )

    ;

  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://sourcecodster.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 - Limit Maximum Post Submit</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-4">
  18. <form method="POST" action="save.php">
  19. <div class="form-group">
  20. <label>Username</label>
  21. <input type="text" name="username" class="form-control" reqired="required"/>
  22. </div>
  23. <div class="form-group">
  24. <label>Password</label>
  25. <input type="password" name="password" class="form-control" reqired="required"/>
  26. </div>
  27. <div class="form-group">
  28. <label>Firstname</label>
  29. <input type="text" name="firstname" class="form-control" reqired="required"/>
  30. </div>
  31. <div class="form-group">
  32. <label>Lastname</label>
  33. <input type="text" name="lastname" class="form-control" reqired="required"/>
  34. </div>

  35. <center><button class="btn btn-primary" name="save">Submit</button></center>
  36. </form>
  37. </div>
  38. <div class="col-md-8">
  39. <table class="table table-bordered">
  40. <thead class="alert-info">
  41. <tr>
  42. <th>Firstname</th>
  43. <th>Lastname</th>
  44. <th>Username</th>
  45. <th>Password</th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. <?php
  50. require

    'conn.php'

    ;
  51. $query

    =

    mysqli_query

    (

    $conn

    ,

    "SELECT * FROM `user`"

    )

    or die

    (

    mysqli_error

    (

    )

    )

    ;
  52. while

    (

    $fetch

    =

    mysqli_fetch_array

    (

    $query

    )

    )

    {
  53. ?>
  54. <tr>
  55. <td><?php

    echo

    $fetch

    [

    'username'

    ]

    ?>

    </td>
  56. <td><?php

    echo

    $fetch

    [

    'password'

    ]

    ?>

    </td>
  57. <td><?php

    echo

    $fetch

    [

    'firstname'

    ]

    ?>

    </td>
  58. <td><?php

    echo

    $fetch

    [

    'lastname'

    ]

    ?>

    </td>
  59. </tr>
  60. <?php
  61. }
  62. ?>
  63. </tbody>
  64. </table>
  65. </div>
  66. </div>
  67. </body>
  68. </html>

Creating the Main Function

This code contains the main function of the application. This code will prompt a warning when the button is clicked. To do that just copy and write this block of codes inside the text editor, then save it as save.php.
  1. <?php
  2. require_once

    'conn.php'

    ;

  3. if

    (

    ISSET

    (

    $_POST

    [

    'save'

    ]

    )

    )

    {
  4. $username

    =

    $_POST

    [

    'username'

    ]

    ;
  5. $password

    =

    $_POST

    [

    'password'

    ]

    ;
  6. $firstname

    =

    $_POST

    [

    'firstname'

    ]

    ;
  7. $lastname

    =

    $_POST

    [

    'lastname'

    ]

    ;


  8. $query

    =

    mysqli_query

    (

    $conn

    ,

    "SELECT * FROM `user`"

    )

    or die

    (

    mysqli_error

    (

    )

    )

    ;
  9. $row

    =

    mysqli_num_rows

    (

    $query

    )

    ;

  10. if

    (

    $row

    <

    5

    )

    {
  11. mysqli_query

    (

    $conn

    ,

    "INSERT INTO `user` VALUES('', '$username

    ', '$password

    ', '$firstname

    ', '$lastname

    ')"

    )

    or die

    (

    mysqli_error

    (

    )

    )

    ;
  12. header

    (

    'location:index.php'

    )

    ;
  13. }

    else

    {
  14. echo

    "<script>alert('You have reached the maximum limit of 5 post \\

    nPlease delete some data first!')</script>"

    ;
  15. echo

    "<script>window.location='index.php'</script>"

    ;
  16. }
  17. }
  18. ?>

There you have it we successfully created Limit Maximum Post Submit 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 the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,513

356,535

356,560

Top
Raidforums