Why this is not running when I add FOREACH

<form class="form-horizontal" method="post">
	
	<?php foreach($array as $row): ?>

           <div class="form-group">
              <label for="name" class="col-md-2 control-label">Name</label>
              <div class="col-sm-6">
                    <input type="text" class="form-control"  value = "<?php echo $row['member_first_name']; ?>"  name = "nameInput"  id="nameInput" placeholder="Name">
              </div>
          </div>
    <?php endforeach; ?>
</form>

I also have this at the top of the code:

<?php

session_start();
require_once ('database_initialisation.php');
include("header.html");
include("menu.html");

$table = "members";
$m_id = $_POST['idInput'];
$array = $admin_query->viewRecordData($m_id, $table);

?>

The above code just gets the Input ID and sends the ID and TABLE, so it tells the function from which table to get what row, and then return it and display it in the FOREACH.

When I try to take out the foreach the field is displayed.
Any idea where the problem might be?

I guess your method viewRecordData() returns single row from table (because it requires id) so there is no need to use foreach to display single row.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.