The not working and i get the same error output as defined in the last else statement.
I am new to Php, please help me out. What am I doing wrong?
HERE IS THE CODE
<form action="imagespace.php?groupid=<?php echo $_GET['groupid'] ;?>" method = "POST">
<input type="button" name="Up-Vote" value ="Up-Vote" class="up-votes" />
<input type="button" name="Down-Vote" value="Down-Vote" class="down-votes" />
</form>
<?php
$emailid=$_SESSION['emailid'];
$groupid = $_GET['groupid'];
$emailid = mysqli_real_escape_string($con,$emailid);
$groupid = mysqli_real_escape_string($con,$emailid);
if(isset($_POST['Up-Vote']))
{ echo ' trial';
$query = "INSERT into VOTES (emailid, groupid, vote) values ('$emailid','$groupid', '1') ";
$query_run = mysqli_query($con,$query);
if($query_run)
{echo 'upvoted';}
}
else if(isset($_POST['Down-Vote']))
{
$query = "INSERT into VOTES (emailid, groupid, vote) values ('$emailid','$groupid', '0') ";
$query_run = mysqli_query($con,$query);
if($query_run)
{echo 'downvoted';}
}
else{
echo 'error' ;
}
}
?>
</body>
</html>
In addition to the supplied answer(s), I would like to suggest doin the following:
// Before anything else, start your session
if (!isset($_SESSION)) {
session_start();
}
// Next, check if your form is actually submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['...'])) {
} elseif (isset($_POST['...'])) {
}
}
?>
<!-- Keep PHP and html seperated -->
<form>
...
</form>
By looking at your form, i notice that you are using type='button'
. I suggest one of the following:
<input type="submit" ... />
<button type="submit">...</button>
I can't seem to find a submit button in there. Try adding
<input type="submit" />
right before the closing </form>
-tag. Then try if the error still occurs if you click on it.
Also, try using checkboxes/radio buttons instead of buttons. I don't know whether it is possible to do that with buttons.
The extra submit button isn't needed, the <button>
s act same in default type.