<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.
@karentutor1: when you post code on the forums, you need to format it so it will display correctly.
You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.
I have figured it out, the suggestion up above cracked it for me.
Thanks!
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$trimmed = array_map('trim', $_POST['username']);
foreach ($trimmed as $value)
{
//echo $value;
if (preg_match ('xx', $value)) {
echo $value . '<br />';
}
else echo 'Please enter username at least 4 characters long and containing letter or number characters';
}
}
<?php
$a = 0;
while ($a == $x)
{
echo '<input type="text" name="username[]">';
}
?>
in this code you will recive on post request in single array of username
like $a = $_POST['username'];
then you will have all value of textboxces in array
your mistake is in this line :
<input class-"text-primary" type="text" class="form-control" name="username<?php$i;?>" maxlength="40" id="usernameField" placeholder="Your Username" />
in name you have given ' username<?php$i?>'
this is not good way still if you want to do like then you have to like
name = username<?=$i?>
or
name = username<?php echo $i; ?>
in these method you will recive this username in post request like
$_POST['username1']
$_POST['username2']