Forum Moderators: coopster
<?php
// The ID will be declared in the URL, for example: "editagent.php?id=4"
$getid = $_GET['id'];
$firstname = $_POST['firstname'];
$submit = $_POST['submit'];
$query = mysql_query('SELECT firstname FROM agents WHERE id = "' . $getid . '"');
$rows = mysql_fetch_assoc($query);
$firstnamedb = $rows['firstname'];
echo '<form action="editagent.php?id=' . $getid . '" method="post"><br />
<input type="text" name="firstname" value="' . $firstnamedb . '"><br />
<input type="submit" name="submit">';
if ($submit)
{
// Edit the data
$updatequery = mysql_query('UPDATE agents SET firstname = "' . $firstname . '" WHERE id = "' . $getid . '"');
echo 'The data has updated successfully.';
}
?> $delete = mysql_query('DELETE FROM agents WHERE id = "' . $getid . '"');
function get_form($action,$id=null) {
//
$table = 'agent_records';
// Get the field names for the agent table so you
// can explicitly initialize values to null, squelching warnings
$fieldnames = get_field_names($table);
foreach ($fieldname as $field) { $agt_values[$field]=null; }
//
if ($action=='edit_form') {
if ($id > 0) {
// Query the DB here so you can populate the form
// with preset values. This idea would return the
// recordset in an associative array "$agt_records"
// which would now overwrite the null values set above.
$agt_records= get_specific_record($table,'id',$id);
}
else { die("You want to edit, but no id!"); }
$recfield = "<input type=\"hidden" name=\"id\" value=\"$id\">";
$button = 'Edit data for ' . $agt_values['fname'] . ' ' . $agt_values['lname'];
}
else {
$recfield=null;
$button = 'Add Record';
}
// Build the form. As I said, "cliff notes." :-)
$form = '
<form action="yourscript.php" method="post">
' . $recfield .
'<input type="hidden" name="frm_action" value="' . $action . '">
'<p><label for="fname">First Name</label>
<input type="text" name="fname" id="fname" value="' .
$agt_values['fname'] . '"></p>
<p><input type="submit" value="' . $button . '"></p>
</form>
';
return $form;
}