well lucky for you i use what you are looking for, except when they click on "update" i go to another page, but i will give you what i have.
this is all on one page, displayed in order. Please let me know if this doesnt work.
Information that is displayed in table with Update and delete.
PHP Code:
<?php
mysql_connect("host","user","pass");
mysql_select_db("db");
$color1 = ""; // color of row 1
$color2 = "#FFFFFF";// color of row 2
$row_count = 0;
$result = mysql_query("SELECT * FROM tblname ORDER BY whatever");
while($row = mysql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2; //alternate row color
$row_count++;
$id = $row['id']; // gets the id for the row that you want to edit when you click "update"
echo"
<table cellSpacing='0' cellPadding='0' width='100%' border='0'>
<tbody>
<tr bgcolor='$row_color'>
<td>Name:</td>
<td>Email:</td>
<td>Testimonial:</td>
<td>Status:</td>
<td><a href=\"page.php?id=$id\">Update</a></td>
<td><a onClick=\"return confirm("Are You Sure?")\" href=\"page.php?action=del&id=$id\">Delete</a></td>
</tr>
</tbody>
</table>";// closing of echo
}
if($_REQUEST['action']=="del") {
mysql_query("DELETE FROM $table WHERE id={$_REQUEST['id']};");
}
?>
The update form
PHP Code:
<?php
$con = mysql_connect("host","user","pass");
if(!$con) {
die('Could not connect: ' . myslq_error());
}
mysql_select_db("db", $con);
$sql = "SELECT * FROM table WHERE id=$_GET[id]"; // gets in id and table name from Update click
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<form action="page.php" method="post">
<table cellSpacing="0" cellPadding="3" width="100%" border="0">
<tbody>
<tr>
<td>ID:</td>
<td><input size="65" type="text" name="id" value"<?php echo $row['id'] ?>"></td>
</tr>
<tr>
<td>Name:</td>
<td><input size="65" type="text" name="tn" value"<?php echo $row['tn'] ?>"></td>
</tr>
<tr>
<td>Email:</td>
<td><input size="65" type="text" name="acct_number" value"<?php echo $row['acct_number'] ?>"></td>
</tr><tr>
<td>Testimonial:</td>
<td><input size="65" type="text" name="port" value"<?php echo $row['port'] ?>"></td>
</tr><tr>
<td>Status:</td>
<td><input size="65" type="text" name="fqdn" value"<?php echo $row['fqdn'] ?>"></td>
</tr>
<tr>
<td>Submit</td>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</tbody>
</table>
The submit section
PHP Code:
<?php
if(isset($_POST['submit'])) {
$con = mysql_connect("host","user","pass");
if(!$con) {
die('Could not connect: ' . myslq_error());
}
mysql_select_db("db", $con);
mysql_query("UPDATE table SET tn = '$_POST[tn]', acct_number = '$_POST[acct_number]', port = '$_POST[port]', fqdn= '$_POST[fqdn]' WHERE id = '$_POST[id]'");
mysql_close($con);
}
?>
Bookmarks