Jump to content
Larry Ullman's Book Forums

For Statement For Create Html Input Boxes Retreived By $_Post Array


Recommended Posts

Hi

I am trying to use a For statement to create multiple input boxes:

<?php for ($i = 1; $i <= $x; $i++);?><post Form><input class-"text-primary" type="text" class="form-control" name="username<?php$i;?>" maxle    ngth="40" id="usernameField" placeholder="Your Username" />

<submit type button>
And then retreiv the results using POST

if ($_SERVER['REQUEST_METHOD'] == 'POST'){        $trimmed = array_map('trim', $_POST);        for ($j = 1; $j < $attendeeNO; $j++){        // Check for a username:        if (preg_match ('/^\w{4,20}$/', $trimmed["username$j"])) {                $un = mysqli_real_escape_string ($dbc, $trimmed["username$j"]);        } else {                echo '<p class="error">Please enter username' .$j. '!</p>';        }}}

However, I cannot seem to retreive the HTML form input boxes and mainpulate them with the $_POST array.

 

The error is that the index is undefined?

 

The problem is that the index is not correctly being passed to the post array upon submission. I have been trying various forms of quotation for the submission but am wondering if I am correctly retrieving / looping through the $_POST form upon submission.

Any thoughts?

 

Thanks,
Karen

 

Link to comment
Share on other sites

You're missing an "echo" in your PHP statement. But what I normally do is make the name just username[] and then you can loop through $_POST['username'], which is an array, to get all the submissions. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...