0

有人可以帮我解决这个问题,因为我真的要疯了!

我有追随者;

.........Some code and then,

      <?php

        if(isset($_POST['sendone']))
        {   if(!isset($_POST['delz']))
            {echo 'No check boxes are selected!'; return;} else 
            {
            $mohan = "<table border='1' cellspacing='0' cellpadding='1' id='brQndTab' class='brndTa'>";
            foreach($_POST['delz'] as $delz)
                        {
                            $delz=mysqli_real_escape_string($db,$delz);
                            $QR = "SELECT bname, bvariant, bsku FROM brands WHERE id='$delz'";
                            $rr = mysqli_query($db,$QR) or die ("SQL Error");
                            $roV = mysqli_num_rows($rr);
                            $rr = $rr->fetch_assoc();

                            $mohan .= "<tr class='sc_eght' ><td class='sc_five'>".$rr['bname']." ".$rr['bvariant']." ".$rr['bsku'];
                            $mohan .="</td>
                               <td><textarea  style='width:80px;' name='schema[]' id='vtext' class='sc_one' rows='1' cols='1' maxlength='100'></textarea></td>
                               <td><input  style='width:80px;' type='text' name='allocas[]' id='vtext' class='sc_two' size='80' maxlength='5'></td>
                               <td><input  style='width:80px;' type='text' name='channelz[]' id='vtext' class='sc_three' size='120' maxlength='30'></td>
                               <td><input  style='width:80px;' type='text' name='provinz[]' id='vtext' class='sc_four' size='120' maxlength='30'></td>
                               </tr>";

                        }
                            $mohan .= "<form method='post' action=''><input type='submit' name='sendMe' id='sendMe' value='Save'></form></table>";
                            $_SESSION['cb'] = $mohan; }

                            if(isset($_SESSION['cb'])) 
                            echo $_SESSION['cb']; 
        }   

        if(isset($_POST['sendMe'])) 
        {       
            if($_POST['provinz'] == '')
            {echo $_SESSION['cb']; echo "Province is empty!"; return;} else { echo $_SESSION['cb']; echo "Saved!"; return;}

            if($_POST['allocas'] == '')
            {echo $_SESSION['cb']; echo "Allocation is empty!"; return;} else   { echo $_SESSION['cb']; echo "Saved!"; return;}

        }

        ?>

…………

问题是何时sendMe提交;

  1. 给我和错误Notice: Undefined index: provinz in C:\xampp\htdocs\docs\add_invoice\testmm.php on line 104
  2. 即使我尝试通过if(isset($_POST['sendMe']))似乎不是正确的方法来获取动态表文本框的值。任何建议都会很棒。

有人可以在这两件事上帮助我吗?如果我的问题不清楚,请发表评论,以便我尽我所能淡化歧义。谢谢

4

1 回答 1

1

基本上$_POST['sendMe']是设置但$_POST['provinz']不是由 PHP 设置或定义的,您需要在对值使用比较运算符之前检查其设置==

你可以这样做:

if(!isset($_POST['provinz']) || $_POST['provinz'] == '')

或者干脆使用empty()

<?php 
if(isset($_POST['sendMe'])){
    $error = array();

    // provinz
    if(!empty($_POST['provinz'])){
        $provinz = $_POST['provinz'];
    }else{
        $error['provinz'] = $_SESSION['cb']." Province is empty!";
    }

    // allocas
    if(!empty($_POST['allocas'])){
        $allocas = $_POST['allocas'];
    }else{
        $error['allocas'] = $_SESSION['cb']." Allocation is empty!";
    }

    // finally process the variables if no error
    if(empty($error)){
        //do something with
        $provinz;
        $allocas;
        echo "Saved!";
    }
}
?>

然后在某处显示错误,您将有一系列与您的键匹配的错误:

<?php echo isset($error['allocas']) ? $error['allocas'] : null ?>

于 2013-06-15T09:28:23.233 回答