Whats the best way to share a form between add & edit re
Posted: Wed Aug 10, 2005 5:14 pm
Hi,
Whats the best way to share one form for add new record or edit a record?
The following shows the form when edit is used, but shows blank page on add new record:
Cheers
Whats the best way to share one form for add new record or edit a record?
The following shows the form when edit is used, but shows blank page on add new record:
Code: Select all
<?php
if (isset($_GET['edit'])) {
$sql = mysql_query("SELECT * FROM table WHERE id='".$_GET['id']."'");
while ($row = mysql_fetch_array($sql)) {
$fname = $row['fname'];
$lname = $row['lname'];
}
?>
<form name="form" method="post" action="somewhere.php">
<table width="36%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="27%"><div align="right">First Name</div></td>
<td width="73%"><input name="fname" type="text" value="<?php echo $fname; ?>"></td>
</tr>
<tr>
<td rowspan="2" valign="top"> <div align="right">Last Name</div></td>
<td><input type="text" name="lname" value="<?php echo $lname; ?>"></td>
</tr>
<tr>
<td><div align="right">
<input name="action" type="hidden" value="<?php echo $_POST['edit']; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="Submit" value="Submit"></div></td>
</tr>
</table>
</form>
<?php
if (isset($_GET['edit'])) {
}
}
?>Cheers