Forum Moderators: coopster
ive tried header("Location: $_SERVER['PHP_SELF']... blah etc
but not working.
some code from form:
echo "<td><input type=\"submit\" value=\"Update\" name=\"button1_$id\" onclick='return confirm(\"Are you sure you want to update this?\")'></td>";
would i include something in the update if (isset[.. {.. area?
ive tried cut and pasting the main query, but nothing.
// See below for notes on this first line
if (isset($_GET['rec'])) { $current_id=$_GET[rec]; }
if (isset($current_id)) {
// open database
// get text for $current_id, store in $text
$recordfield = '<input type="hidden" name="current_id" value="' . $current_id . '">';
$action="update";
}
else {
$text='';
$action="add";
$recordfield = '';
}
$form = '
<form action="yourscript.php" method="post">
<input type="hidden" name="action" value="' . $action . '">' .
$recordfield .
<input type="text" name="txtval" id="txtval" value="' . $text . '">
</form>
';
echo $form;
So if action is add, you insert and get the record ID, store in $current_id. When it returns to the page, it goes into "edit" mode, will open the database record, and your script should do an update based on the action being "update."
One might think this is an easier solution,
<input type="text" name="txtval" id="txtval" value="' . $_POST['txtval'] . '">
But this is no indicator it properly inserted or updated. Additionally, if you are choosing this form out of an edit link,
<a href="yourscript.php?rec=1234">Edit 1234</a>
You will need to set and get the data for this record for editing, and there is no post data for the text field, it will be blank.
One other bit of advice,
<input type=\"submit\" value=\"Update\" name=\"button1_$id\" onclick='return confirm(\"Are you sure you want to update this?\")'>
What happens when the user presses the enter key? I'll tell you. It submits without the confirm. Put your handler on the form:
$form = '
<form action="yourscript.php" action="post" onSubmit="return confirm(\'Are you sure you want to update this?\')">
<input type="submit" value="Update" name="button1_' . $id . '">
</form>';
echo $form;