Search the Community
Showing results for tags 'form if isset'.
-
this page is used to display, add, edit and delete records from a table called 'valid_locations' so far, I can display the contents of the table (2 colums, 'id' and 'location') and the edit/delete button associated with each record. but when I click the edit button, the page displays the "confirm changes" button but no form elements to edit (from the section "//edit form" I'm stuck at this point and don't know where or how to go about moving forward. Cheers Zach <?php $pagetitle="Locations"; $menu="yes"; require 'header.php'; require 'dbvars.php'; require 'dafunc.php'; //set the referrer variable $self=htmlentities($_SERVER['PHP_SELF']); // Make a MySQL Connection $con=mysqli_connect($sqlhost,$sqluser,$sqlpass,$sqldb); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //edit form if(isset($_POST['edit'])) { $id=$_POST['id']; $result = mysqli_query($con,"SELECT * FROM valid_locations WHERE id='$id'"); echo "$id"; if($result === false){ throw new Exception(mysqli_error($con)); } echo "<form action=\"$self\" method=\"post\">"; echo "<table>"; while($row = mysqli_fetch_array($result)) { echo "<tr><td>ID</td><td>" . $row['id'] . "</td></tr>"; echo "<input name=\"id\" type=\"hidden\" value=\"" . $row['id'] ."\" />"; echo "<tr><td>Location</td><td><input name=\"location\" type=\"text\" value=\"". $row['location'] ."\"/></td></tr>"; } echo "</table>"; echo "<input type=\"submit\" name=\"confirm\" id=\"confirm\" value=\"Confirm Changes\" />"; echo "</form>"; } //write the changes to the DB if(isset($_POST['confirm'])) { echo "write the changes to the database!"; } //delete a record if(isset($_POST['delete'])) { echo "delete the record!"; } //display the table containing the valid locations $result = mysqli_query($con,"SELECT * FROM valid_locations"); echo " <form action=\"$self\" method=\"post\"> <table> <tr><th>ID</th><th>Location</th></tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<input type=\"hidden\" name=\"id\" id=\"" . $row['id'] . "\">"; echo "<td>" . $row['location'] . "</td>"; echo "<input type=\"hidden\" name=\"location\" id=\"" . $row['location'] . "\">"; echo "<td><input type=\"submit\" name=\"edit\" id=\"edit\" value=\"Edit\" /></td>"; echo "<td><input type=\"submit\" name=\"delete\" id=\"delete\" value=\"Delete\" /></td>"; echo "</tr>"; } echo "</table>"; echo "</form>"; mysqli_close($con); ?> </body> </html>