Undermine2k
Undermine2k

Reputation: 1491

PHP form output

I'm generating this table from data passed back from my controller the issue I'm having is that in general the first record returned [ in this case Sephen C. Cox], the "add employee" button does not redirect me but for the rest of the records it works. Does anyone know the problem?

enter image description here

<fieldset id= "results">                
<?php if (isset($results ) And count($results)) : ?>
<table id="box-table-a" summary="Employee Sheet">
        <thead>
            <tr>
                <th scope="col">Employee</th>
                <th scope="col">Salary</th>
                <th scope="col">Bonus</th>
                <th scope="col">Supervisor</th>
                <th scope="col">Action</th>
                </tr>


    <?php foreach ($results as $result) : ?>
    <tr>
    //Primary key <?php echo $result['Employee_ID!'];?>
    <td><span class="Employee_name"><?php echo $result['Employee']; ?> </span></td>         
    <td><span class="Salary"><?php echo $result['Salary']; ?> </span> </td>
    <td><span class="Bonus"><?php echo $result['Bonus']; ?> </span> </td>
    <td><span class="Supervisor_name"><?php echo $result['Supervisor']; ?> </span></td>
    <form action="welcome.php" method="post">   <td><input type="submit" value="Add employee" name="submit[<?php echo $result['Employee_ID'] ?>]" > </td></form>
    </tr>

        <?php endforeach; ?>
        <?php endif; ?>
        </thead>
        <tbody>
        </fieldset>

Upvotes: 0

Views: 154

Answers (1)

Viktor S.
Viktor S.

Reputation: 12815

<form action="welcome.php" method="post">
  <td>
     <input type="submit" value="Add employee"
     name="submit[<?php echo $result['Employee_ID'] ?>]" > 
 </td></form>

change to

<td>
 <form action="welcome.php" method="post">
     <input type="submit" value="Add employee"
     name="submit[<?php echo $result['Employee_ID'] ?>]" >
  </form>

Or even wrap the whole table into one form instead of putting new form into each row. See no any reason in your code why that could be needed

Edit: Also, take a look at tools like Firebug (FF), Inspector in Chrome and Safary, Developer Tools, or how it is called, in IE. It was completely enough to open you page with one of those tools and notice that browser parsed your code not like you expected.

Upvotes: 2

Related Questions