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

Simple Voting System

klafjkl

Social Persona Designer
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
154
Likes
106
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
This tutorial will teach you how to create a simple voting system in PHP. And it has a two user side, the student and the admin, for the student side is were the user vote there candidate while for the admin is the control unit of the system that can edit, update, and see the results or count of all the candidates. This simple voting system is creating a vote candidates and position, and it generates result for all the candidates that the user voted.

Sample Code

Script for the Vote Process
  1. <?php
  2. session_start

    (

    )

    ;
  3. mysql_connect

    (

    'localhost'

    ,

    'root'

    ,

    ''

    )

    ;
  4. mysql_select_db

    (

    'vote'

    )

    ;

  5. if

    (

    isset

    (

    $_POST

    [

    'vote'

    ]

    )

    )
  6. {
  7. $query

    =

    mysql_query

    (

    "SELECT * FROM position ORDER BY position_id ASC"

    )

    or die

    (

    mysql_error

    (

    )

    )

    ;

  8. if

    (

    mysql_num_rows

    (

    $query

    )

    >

    0

    )
  9. {
  10. while

    (

    $row

    =

    mysql_fetch_array

    (

    $query

    )

    )
  11. {
  12. $position

    =

    $_POST

    [

    'position_'

    .

    $row

    [

    'position_id'

    ]

    ]

    ;
  13. mysql_query

    (

    "INSERT INTO votes (candidate_id,student_id) VALUES ('$position

    ','"

    .

    $_SESSION

    [

    'student_id'

    ]

    .

    "')"

    )

    or die

    (

    mysql_error

    (

    )

    )

    ;
  14. }
  15. }
  16. $_SESSION

    [

    'checkVote'

    ]

    =

    1

    ;
  17. header

    (

    "location: home.php"

    )

    ;
  18. }
  19. ?>

sadas.jpg


Hope you learn it and enjoy coding. Thanks.


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

452,292

324,186

324,194

Top