I'm having an issue with a form inside my table. I created a table that shows a list of recent status's that the people the user follows posts. I created a form inside the table so the community can "like" or "unlike".
Every time I try to submit the form, the post is being posted in the URL and stops at my button name "likestatus="
example of the URL returned:
account.php?likesid=5&likerid=117&likestatus=
The input of the form works, as each button shows the corresponding "likesid" and "likerid" in the URL
I just don't understand why it's failing.
Here is the code for my "$_POST['likestatus']"
<?php
if(isset($_POST['likestatus']))
{
//inputs from the form
$likesid =mysqli_real_escape_string($conn, $_POST['likesid']);
$likerid =mysqli_real_escape_string($conn, $_POST['likerid']);
//query to check if already likes status
$sql = "SELECT likesid, likerid FROM user_likes WHERE (likesid='$likesid') AND (likerid='$likerid')";
$result = mysqli_query($conn, $sql);
$alreadylike = mysqli_num_rows($result);
if ($alreadylike > 0) {
echo "You already liked this status";
}
else {
$hostname = "localhost";
$username = "root";
$password = "changed for post";
$databaseName = "changed for post";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
//inputs from the form
$likesid =mysqli_real_escape_string($connect, $_POST['likesid']);
$likerid =mysqli_real_escape_string($connect, $_POST['likerid']);
//query to insert into table
$query = "INSERT INTO `user_likes` SET `likesid`='".$likesid."', `likerid`='".$likerid."'";
$result = mysqli_query($connect, $query);
if($result)
{
echo 'updated';
}
else
{
echo 'not updated';
}
mysqli_close($connect);
}
}
?>
The form code:
<td style="width: 100px;">
<p align="center">
<form action="account.php" method="post">
<input type="hidden" name="likesid" value="<?php echo $statusid; ?>">
<input type="hidden" name="likerid" value="<?php echo $_SESSION['id']; ?>">
<button style="color: #FFFFFF; width: 50%; margin-left: 35px; background-color: transparent; cursor: pointer; text-shadow: 1px 1px 4px #2F3A85" type="submit" name="likestatus">
<label class="myLabel"><span class="w3-xlarge" style="font-family: 'Righteous'; border: 1px; border-radius: 5px; border-color: #FFFFFF;">like</span></label>
</button>
</form></p>
</td>
The page does not return any errors that could point me in any direction, it simply just reloads the page with post info in the URL.
I am assuming the complications start with the fact that the form is inside a table array and maybe the forms submit value is remaining the same throughout all tables?