Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP将文本发布到HTML_Php_Html_Forms_Checkbox - Fatal编程技术网

如何使用PHP将文本发布到HTML

如何使用PHP将文本发布到HTML,php,html,forms,checkbox,Php,Html,Forms,Checkbox,好的,我在这里要做的是检查是否勾选了复选框,如果勾选了,那么我想将文本添加到名为“已确认”的类中 如果没有检查,那么我会将文本添加到名为“unconfirm”的类中。现在我有了检查复选框是否已被确认的php代码(见下文),但我不知道在语句中添加什么。这就是我需要帮助/指导的地方 PHP IF代码(勾选复选框): 以下是我的HTML代码: <body> <div id="content"> <div class="jumbotron"> &l

好的,我在这里要做的是检查是否勾选了
复选框,如果勾选了,那么我想将文本添加到名为“已确认”的
类中

如果没有检查,那么我会将文本添加到名为“unconfirm”的
类中。现在我有了检查复选框是否已被确认的php代码(见下文),但我不知道在语句中添加什么。这就是我需要帮助/指导的地方

PHP IF代码(勾选复选框):


以下是我的HTML代码:

<body>

<div id="content">

    <div class="jumbotron">
  <h1>Is there football on Wednesday?</h1>
  <h2>Yes.</h2>
</div>

<div class="alert alert-info" role="alert">Confirmed Players</div>

<ul class="list-group">
  <li class="list-group-item">
<!--this is where to result of the php code would go if the checkbox is checked-->
    Lorem Ipsor
  </li>

</ul>

<div class="alert alert-danger" role="alert">Unconfirmed Players</div>
  <li class="list-group-item">
<!--this is where to result of the php code would go if the checkbox is not checked-->
    Lorem Ipsor
  </li>
</div>

<!--form-->
<form action="check.php" method="POST">
    <input type="checkbox" name="checkbox1">
    <input type="submit"></input>
</form>

</body>

星期三有足球比赛吗?
对
确认玩家
  • 洛雷姆·伊普索
未经确认的玩家
  • 洛雷姆·伊普索

  • 对不起,如果我像我说的那样把你弄糊涂了,我不太舒服。任何帮助/指导都会很好

    好的,所以当您勾选复选框时,它应该通过$\u POST返回一个值,在提交时为1或0。您可以如下方式修改模板:

    <?php 
        if ($_POST['checkbox1']) {
        $class = 'confirmed';
        } 
        else {
        $class = 'unconfirmed';
        }
    
    ?>
    <body>
    
    <div id="content">
    
        <div class="jumbotron">
      <h1>Is there football on Wednesday?</h1>
      <h2>Yes.</h2>
    </div>
    
    <div class="alert alert-info" role="alert">Confirmed Players</div>
    
    <ul class="list-group <?php echo $class; ?>">
    
      <li class="list-group-item">
        Lorem Ipsor
      </li>
    
    </ul>
    
    <div class="alert alert-danger" role="alert">Unconfirmed Players</div>
    
    </div>
    
    <!--form-->
    <form action="check.php" method="POST">
        <input type="checkbox" name="checkbox1" />
        <input type="submit" />
    </form>
    
    </body>
    
    
    星期三有足球比赛吗?
    对
    确认玩家
    
    如果不使用AJAX,您可以尝试如下嵌套php代码:

    <ul class="list-group">
      <li class="list-group-item">
    <?php
    
    if (isset($_POST["checkbox1"])){
        //write to <ul> class confirmed
        }
    
    
    ?> 
      </li>
    
    </ul>
    
    <div class="alert alert-danger" role="alert">Unconfirmed Players</div>
      <li class="list-group-item">
    <?php
    
    if (!isset($_POST["checkbox1"])){
        //write to <ul> class unconfirmed
        }
    
    
    
    ?> 
      </li>
    
    未经确认的玩家

  • 这真的是关于发布HTML“代码”的吗?因为我觉得这不是真的。请使用合适的术语,这样我们就可以知道你在问什么。@developerwjk是的,对不起,我已经更新了标题。对我来说,你似乎缺少插入/选择数据库部分。所以您可以将确认的人员存储在数据库中,并通过从数据库表中获取结果来显示他们。好的,答案很明显:没有按钮可以发布任何内容。您的表单只有一个复选框。任何基本的HTML教程,即使是不好的,都会显示您需要一个提交按钮。您确实需要转到HTML教程,而不是反复更新问题来创建实时教程。“提交”按钮的语法错误。教程会告诉你原因。鹦鹉学舌的语法错误很好
    。问题与HTML有关。OP不知道基本的HTML。没有答案建议更好的PHP是这个问题的真正答案。@developerwjk我知道基本的HTML。我忘记包含上面的完整代码是一个错误。正如我所说的,我感觉不太好,我注意力不集中是罪魁祸首。
    <ul class="list-group">
      <li class="list-group-item">
    <?php
    
    if (isset($_POST["checkbox1"])){
        //write to <ul> class confirmed
        }
    
    
    ?> 
      </li>
    
    </ul>
    
    <div class="alert alert-danger" role="alert">Unconfirmed Players</div>
      <li class="list-group-item">
    <?php
    
    if (!isset($_POST["checkbox1"])){
        //write to <ul> class unconfirmed
        }
    
    
    
    ?> 
      </li>