Hello, I want to display a table with only a part of the info after Submit, if a name is inserted correctly I want to display the name and it’s role, followed by text “Accepted!”
If name is wrongly inputted i don’t insert it, but I display the name, it’s role followed by text “Try Again!”
All in the same table so u can enter several names at the same time and display if accepted or not… I’ve checked some examples but they are slightly different.
Only one $name is displayed, even if you $_POST two.
Here’s my code:
<?php
include_once 'pdo.php';
if(isset($_POST['submit'])){
$name = $_POST['name'];
$role = $_POST['role'];
$round = $_POST['round'];
$week = $_POST['week'];
$postdate= date('Y-m-d H:i:s.');
for($i=0;$i<count($name) && ($role) ;$i++)
{
if(preg_match("%^[A-Za-z0-9-_]{3,35}$%", $name[$i]))
{
$sql_add = 'INSERT INTO worktable (name,role,round,week,time) VALUES (?,?,?,?,?)';
$stmt_add = $pdo->prepare($sql_add);
$stmt_add->execute(array($name[$i],$role[$i],$round, $week, $postdate));
$arr = array($name[$i],$role[$i],'Accepted!');
} else {
$arr = array($name[$i],$role[$i],'Try again!');
}
}
}
?>
<html>
<head>
<link href="bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col"></div>
<div class="col-md-8"><br><br>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Role</th>
<th scope="col">Status</th>
</tr>
</thead><tbody>
<tr>
<?php foreach($arr as $data): ?>
<td><?php echo $data; ?></td>
<?php endforeach ?>
</tr>
</tbody>
</table>
</div>
<div class="col"></div>
</div>
</div>
</body>
</html>
How do I correctly build this new array and correctly display it? Any material to read o hint. Thanks.