php中的php增量字段值

时间:2016-01-20 12:06:17

标签: php html

<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>

这是我在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);}

这是我在php中的代码

3 个答案:

答案 0 :(得分:1)

名称是'团队'。不,'id'。使用此代码。将id值提供给value属性

<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);}
?>

答案 1 :(得分:0)

你需要将收音机的值更改为id这个平均值='1'

需要改变 $ selected_radio = $ _POST ['id'];  $ selected_radio = $ _POST ['team'];

并将输入类型更改为提交type ='submit'

.sln

我希望这能解决您的问题

答案 2 :(得分:0)

您需要撰写$_POST['team']。试试这个代码: -

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

查看此link了解更多详情。