dongqian6234
2014-11-02 23:45
浏览 42
已采纳

复选框,提交按钮不起作用

I have a page where if the checkbox is checked then it should echo "g". I know that the echoing "g" works because I tired it with only pressing the button.

<? require("Left.php"); ?>
<? include_once("connect.php"); ?>
<form method="post" >
<input type="submit" name="submit" id="submit" value="submit">
<?php
if($ownstarter = true){
echo 'User starter';
echo "<input type='checkbox' name='checkbox' id='checkbox'>";
}
?>
</form>
<?
 if (isset($_POST['submit'])) {
    if ($_POST['test'] == 'checkbox') {
        echo 'g';
}
}
?>
<? require("Right.php"); ?>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujue1246 2014-11-02 23:51
    已采纳

    you are testing for the 'test' variable in POST, but ure sending the 'checkbox'
    if you want to send a variable for 'checkbox' set attribute 'value=""' in the checkbox. Then you can do this:

     if (isset($_POST['submit'])) {
         if ($_POST['checkbox'] == 'yourValue') {
             $gold = $gold +5;
        }
    }
    

    otherwise do this:

     if (isset($_POST['submit'])) {
         if (isset($_POST['checkbox'])) {
             $gold = $gold +5;
        }
    }
    
    打赏 评论

相关推荐 更多相似问题