有人可以帮助我,因为我真的疯了!
我有跟随者;
.........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
时
Notice: Undefined index: provinz in C:\xampp\htdocs\docs\add_invoice\testmm.php on line 104
if(isset($_POST['sendMe']))
获取动态表格文本框的值似乎也不是一种正确的方法。任何建议都会很棒。 有人可以帮我解决这两件事吗?如果我的问题不清楚,请发表评论,以便我尽力淡化模棱两可。感谢
答案 0 :(得分:1)
基本上$_POST['sendMe']
已设置,但PHP未设置或定义$_POST['provinz']
,您需要在对值使用比较运算符==
之前检查其集合:
您可以这样做:
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 ?>