Search the Community
Showing results for tags 'identify'.
-
Hi, I am a PHP noob. I have a table in which I am showing data from a mysql database. I'm using PDO to do the database stuff. Thus far, all good. In the table I have a hidden field that stores my unique identifier for that row. Each row in the table has an 'Edit' button. I am showing the row in a DataTable. I am displaying the data using form text elements so I can make it editable in place. I have all that working. The problem 'I think' is that the form elements in every row have the same name as in every other row. If I show a single record I can change something and click edit and it works fine. If I fill the table with records, then change something in a row and click edit, it doesn't work. I have tried to concatenate an index number onto the names of each field, thus making them all unique, but it still isn't working. Here is some code: try { if(isset($_POST['update'])){ $updatedQuery = "UPDATE fac_detail SET first_name=:fname, last_name=:lname, height=:height ,cap=:cap,colors=:color WHERE employee_id=:hidden"; $stmt = $dbh->prepare($updatedQuery); $stmt->bindParam(':fname', $_POST['firstName'], PDO::PARAM_STR); $stmt->bindParam(':lname', $_POST['lastName'], PDO::PARAM_STR); $stmt->bindParam(':height', $_POST['height'], PDO::PARAM_STR); $stmt->bindParam(':cap', $_POST['cap'], PDO::PARAM_STR); $stmt->bindParam(':color', $_POST['color'], PDO::PARAM_STR); $stmt->bindParam(':hidden', $_POST['hidden'], PDO::PARAM_STR); $stmt->execute(); } $sql = "SELECT * FROM fac_detail"; $stmt = $dbh->prepare($sql); $stmt->execute(); $arrValues = $stmt->fetchAll(PDO::FETCH_ASSOC); $row = $stmt->fetch(); } catch(PDOException $e) { die($e->getMessage()); } echo "<form action=facultyPage.php method= post>"; echo '<table id="recordTable">'; echo '<thead>'; echo '<tr>'; echo "<th>First Name"; echo "<th>Last Name"; echo "<th>Height</th>"; echo "<th>Cap</th>"; echo "<th>Color</th>"; echo "<th>Editable BUTONNNS</th>"; echo '</tr>'; echo '</thead>'; echo '<tbody>'; $num = 0; foreach ($arrValues as $row){ echo "<tr>"; echo "<td>" . "<input type=text name=firstName value=" . $row['first_name'] . " </ td>"; echo "<td>" . "<input type=text name=lastName value=" . $row['last_name'] . " </ td>"; echo "<td>" . "<input type=text name=height value=" . $row['height'] . " </ td>"; echo "<td>" . "<input type=text name=cap value=" . $row['cap'] . " </ td>"; echo "<td>" . "<input type=text name=color value=" . $row['colors'] . " </ td>"; echo "<td>" . "<input type=hidden name=hidden value='" . $row['employee_id'] . "' /> "; //TODO dropdowns //echo '<td><select name="degree"></td>'; //echo ' <option></option>'; //echo ' <option></option>'; //echo '</select> '; //echo '<td><select name="school" disabled="disabled"></td>'; //echo '<option></option>'; //echo '<option></option>'; //echo '</select>'; echo '<input type="submit" name= "update" value="Update" /></td>'; echo '</tr>'; $num++; } echo '</tbody>'; echo '</table>'; echo "</form>"; I am showing it in a datable, I have that working fine. Each rows form elements have the same names. I think thats where the problem lies. Anyone know an approach or trick I can implement so the submit button knows which row it's on? Thanks in advance...