【问题标题】:PHP accessing $_POST values and count()PHP 访问 $_POST 值和 count()
【发布时间】:2013-08-05 22:04:37
【问题描述】:

我在将编辑内容发布到可变大小的表格时遇到问题。我有一系列行,每行有两个文本框和一个复选框。这些框预先填充了当前值。当用户编辑一个然后单击表格底部的“提交”时,目标是将编辑的行发送到远程数据库,在那里它们将被更改。这是我的表格代码:

<?php

//I set up a socket and send a request for data here
$sent = socket_sendto($socket, $request, strlen($request), 0 , $addr, $port);

if($sent !== FALSE){
    $message = '';
    $next = ''; 
    //bytes to read
    while($next = socket_read($socket, 2000)){
        //custom terminate char sequence
        if($next === $term){
            //get out of if and while
            break 2;
        }else{ $message .= $next;}  
    }
    $fbt = json_decode($message,true);
    $tableCount = count($fbt);
    if($tableCount == 0){
        //notify the user 
        echo "No feedback entries have been defined. Please add some.";
    }else{
        //display the table
        echo "<form name=\"fb\" action=\"fbedit_submit.php\" method=\"post\"><table id=\"opt\"><tbody>";
        for($i=0;$i<$tableCount;$i++){
            //echo the rows

            echo "<tr class=\"optr\"><td class =\"optid\">". 
            "Code: <input name=\"id[".$i."]\" type=\"text\" width=\"20px\" value=\"".$fbt[$i]["id"]."\">".
            "</td><td class=\"optcode\">".
            "Description: <input name=\"desc[".$i."]\" type=\"text\" value=\"".$fbt[$i]["code"]."\">".
            "</td><td class=\"optactive\">".
            "Active: <input name=\"active[".$i."]\" type=\"checkbox\"";
            if($fbt[$i]["active"] == 1){
                echo "checked=\"checked\">";
            } else{
                echo ">";
            }
            //finish lines
            echo "</td></tr>";
        }
        echo "</tbody></table>
            <br><input name=\"fbmodbtn\" id= \"b-submit\" type=\"submit\">
            </form>";
    }

} else{
    echo "Failed.";
}

socket_close($socket);
?>

这段代码运行良好(虽然它有点笨重)。我希望能够在提交时 _POST 表单,但当我这样做时

echo count($_POST['id']);

在操作页面上,我总是得到 0。我收到的错误是:

未定义的索引: id in C:\xampp\htdocs\upt\fbedit_submit.php 上线 14

如何获取表中的行数,然后访问这些值以通过另一个套接字连接发送它们?

【问题讨论】:

  • 您确定不只是缺少_ 之前的POST?
  • 万岁激活 E_NOTICE 错误级别!

标签: php forms count html-table http-post


【解决方案1】:
echo count($POST['id']);

应该是

echo count($_POST['id']);

【讨论】:

  • 谢谢。我的错。我现在有,但问题仍然存在。
猜你喜欢
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 2019-01-05
  • 2012-11-11
  • 2012-07-03
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
相关资源
最近更新 更多