PerroDeAlce
PerroDeAlce

Reputation: 37

PHP accessing $_POST values and count()

I am having a problem posting edits to a table of variable size. I have a series of rows with two text boxes and a check box in each row. The boxes are pre-filled with current values. When a user edits one and then clicks "submit" at the bottom of the table, the goal is to send the edited rows to the remote database where they will be changed. Here is my table code:

<?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);
?>

This code works well (though it is a little bulky). I want to be able to _POST the form when I submit but when I do

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

on the action page, I always get 0. The error I receive says:

Undefined index: id in C:\xampp\htdocs\upt\fbedit_submit.php on line 14

How can I get the number of rows in my table and then access the values to send them via another socket connection?

Upvotes: 0

Views: 2413

Answers (1)

SeanCannon
SeanCannon

Reputation: 77956

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

should be

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

Upvotes: 3

Related Questions