I have been looking around on the forum and tried everything but I cant get my button to disable after clicking it, I just started using php and this is one of my first projects. Its a like and dislike system. Does anyone know the awnser? when you press a like button or dislike button I want both buttons to be disabled.
<!--Like System-->
<center>
<?php
$sql = "SELECT * FROM likes";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?> <h1 class="lcount"><?php echo $row["average"];?> <span class="glyphicon glyphicon-signal"></span></h1></br><?php
}
} else {
echo "0 results";
}
?>
<?php
$sql = "SELECT * FROM likes";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?> <h1 class="lcount"><?php echo $row["like"];?>
<span style="color: green;"class="glyphicon glyphicon-thumbs-up"></span></h1></br>
<?php
}
} else {
echo "0 results";
}
?>
<?php
$sql = "SELECT * FROM likes";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?> <h1 class="lcount"><?php echo $row["dislike"];?>
<span style="color: red;" class="glyphicon glyphicon-thumbs-down"></span></h1>
<?php
}
} else {
echo "0 results";
}
?>
<?php
if(isset($_POST['like'])){
$sql = "UPDATE `likes` SET `like` = `like` + 1 , `average` = `average` + 1";
if (mysqli_query($con, $sql)) {
} else {
echo "Error updating record: " . mysqli_error($con);
}
}
?>
<?php
if(isset($_POST['dislike'])){
$sql = "UPDATE `likes` SET `dislike` = `dislike` + 1 , `average` = `average` - 1";
if (mysqli_query($con, $sql)) {
} else {
echo "Error updating record: " . mysqli_error($con);
}
}
?>
<form type="#" method="post">
<button name="like" type="submit" class="btn btn-success">
<span class="glyphicon glyphicon-thumbs-up"></span></button>
<button name="dislike" type="submit" class="btn btn-danger">
<span class="glyphicon glyphicon-thumbs-down"></span></button>
</form>
</center>
<!--Like System END-->