To create this simple voting system, it is necessary to have made in a reasonable MySql database with an established connection.
Also, it is necessary to create a table in the database


Create MySql database "demo"

<?php
$servername 
"localhost";
$username "yourusername";
$password "yourpassword";
$conn = new mysqli($servername$username$password);
if (
$conn->connect_error) {
    die(
"Connection failed: " $conn->connect_error);

$sql "create database demo";
if (
$conn->query($sql) === TRUE) {
    echo 
"Database demo created successfully";
} else {
    echo 
"Error creating database: " $conn->error;
}
$conn->close();
?>


Create MySql table "votes"

<?php
$con
=mysqli_connect("localhost","yourusername","yourpassword","demo");
if (
mysqli_connect_errno()) {
  echo 
"Failed to connect to MySQL: " mysqli_connect_error();
}
$sql "CREATE TABLE votes(id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
rating INT(11)NOT NULL)"
;
if (
mysqli_query($con,$sql)) {
  echo 
"Table `votes` created successfully";
} else {
  echo 
"Error creating table: " mysqli_error($con);
}
?>

The data in the table can insert manually using phpmyadmin or using php code for insert data to MySql table. For example:



<?php
$conn
=mysqli_connect("localhost","yourusername","yourpassword","demo");
if (
mysqli_connect_errno()) {
echo 
"Failed to connect to MySQL: " mysqli_connect_error();
}
$sql "INSERT INTO votes (id,rating) 
VALUES     (`1`,`0`),
           (`2`,`0`),
           (`3`,`0`) "
;
if (
mysqli_query($conn$sql)) {
echo 
"New record created successfully";
} else {
echo 
"Error: " $sql "<br>" mysqli_error($conn);
}
mysqli_close($conn);
?>


Create file "voting.php"
 
<?php
 $con
=mysqli_connect("localhost","yourusername","yourpassword","demo");
if (
mysqli_connect_errno())
  {
  echo 
"Failed to connect to MySQL: " mysqli_connect_error();
  }
 
$result mysqli_query($con,"SELECT id, rating FROM votes WHERE id=1");
 while (
$row mysqli_fetch_array($result))
  {
   echo 
$row["rating"] ;
  echo 
"<br>";
  }
?>

<form action="voting.php" method="post">  
<input type = "submit" value = "vote" name="rating"/>
</form>
 
<?php
 $con
=mysqli_connect("localhost","yourusername","yourpassword","demo");
 if (
mysqli_connect_errno())
  {
  echo 
"Failed to connect to MySQL: " mysqli_connect_error();
  }
 if(
$_POST["rating"]) {
 
$ql=mysqli_query($con,"UPDATE votes SET rating=rating+1 WHERE id=1 ");
  }
?>

an electronic voting system in php (YouTube)