How to - Insert / Update - using the same form?

I will have a list of records, on that list of records, if the users clicks on a specific record link it will be redirected to the insertEdit form page.

Here’s an outline:

Links to edit records. Pass the ID in the URL (this is genuine GET usage)


<ul>
   <li><a href='insertEdit.php?id=1'>Edit 1</a></li>
   <li><a href='insertEdit.php?id=2'>Edit 2</a></li>
   <li><a href='insertEdit.php?id=3'>Edit 3</a></li>
</ul>

insertEdit page — build the form


<form method="post" action="insertEdit.php">
<p style="display: none;">
<?php
//hidden input with ID of entity or 0 to add new
$id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0;
echo "<input type='hidden' name='id' value='$id'>";
?>
</p>

<input type="text" name="blah" value="blah blah">
</form>

Then when processing the form you look at $_POST[‘id’]. If it’s 0 you are adding a new record, if it’s an int, that’s the id of the entity you’re editing.

Throwing bombs don’t count. :eek: :eek:

So, not only we should use POST for posting data and GET for getting data.
(that always confuse me, when I read that POST and GET weren’t really meant “post” and “get”).

So we can use a REST approach on the way we interact on our websites, on the websites we develop?

Can we actually do this?

if you want to delete a record from a database you use a HTTP DELETE request

From 2001 but seems to be well founded:
http://www.cs.tut.fi/~jkorpela/forms/methods.html

The topic:
The fundamental differences between “GET” and “POST”

Seems to be accurate on underlying the differences. I don’t know if they still apply.

Can you please clarify a bit more about the relations between my question and the REST so that I can properly understand is place here.

Thanks in advance,
Márcio