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 IF NOT EXISTS votes (
    id INT AUTO_INCREMENT,
    rating INT(11) NOT NULL,
    PRIMARY KEY (id));"
;
    
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(rating)
VALUES(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
$servername 
"localhost";
$username "yourusername";
$password "yourpassword";
$dbname "databasename";
$conn mysqli_connect($servername$username$password$dbname);
if (!
$conn) {
    die(
"Connection failed: " mysqli_connect_error());
}

if(
$_POST["rating"]) {
    
 
$ql=mysqli_query($conn,"UPDATE votes SET rating=rating+1 WHERE id=1 ");
  }

$sql "SELECT id, rating FROM votes";
$result mysqli_query($conn$sql);

if (
mysqli_num_rows($result) > 0) {
    while(
$row mysqli_fetch_assoc($result)) {
        echo 
$row["rating"]."<br><br>";
    }
} else {
    echo 
"0 results";
}
?> 
<form action="voting.php" method="post">  
<input type ="submit"  value ="vote" name="rating"/>
</form>


an electronic voting system in php (YouTube)