0
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <ul> 
        <input type="radio" name="team" id="1" value="Real Madrid" size='5'><font size='5'><u> Real Madrid<br> 
        <input type="radio" name="team" id="2" value="Chelsea"> Chelsea<br> 
        <input type="radio" name="team" id="3" value="Milan"> Milan<br>
        <input type="button" id="submit" name="submit" value="VOTE" >

</form>

this is my button in html

if(isset($_POST['submit'])){
   $selected_radio = $_POST['id'];
   $query = "UPDATE favourite_team SET likes = likes + 1 WHERE id = '" .  $selected_radio . "'";
   $q = mysqli_query($conn, $query);}

this is my code in php

10
  • 2
    Your question is not so clear. What's the error? What you are expecting? Commented Jan 20, 2016 at 12:07
  • What is the issue? Please specify your question so one can able to give proper answer. Commented Jan 20, 2016 at 12:11
  • what have to be done? specify it! Commented Jan 20, 2016 at 12:11
  • I expect when click the button to increase likes with 1. When I click the button nothing happen Commented Jan 20, 2016 at 12:12
  • Show your complete form along with your database connection!! Commented Jan 20, 2016 at 12:13

3 Answers 3

1

Name is 'team'. Not, 'id'. Use this code. Give id value to value attribute

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <ul> 
        <input type="radio" name="team" value="1" size='5'><font size='5'><u> Real Madrid<br> 
        <input type="radio" name="team" value="2" > Chelsea<br> 
        <input type="radio" name="team" value="3" > Milan<br>
        <input type="button" id="submit" name="submit" value="VOTE" >

</form>

<?
if(isset($_POST['submit'])){
   $selected_radio = $_POST['team'];
   $query = "UPDATE favourite_team SET likes = likes + 1 WHERE id = '" .  $selected_radio . "'";
   $q = mysqli_query($conn, $query);}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to write $_POST['team']. Try this code:-

 $selected_radio = $_POST['team'];
 $query = "UPDATE favourite_team SET likes = likes + 1 WHERE id = '" .  $selected_radio . "'";
 $q = mysqli_query($conn, $query);

Check this link for more detail.

Comments

0

you need to change the value of the radio to be the id this mean value='1'

and need to change $selected_radio = $_POST['id']; to $selected_radio = $_POST['team'];

and change input type to submit type='submit'

<input type='submit' id='submit' name='submit' value='VOTE'>

i hope this will fix your problem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.