Home » Php » Record Update – PHP

Record Update – PHP

Posted by: admin February 23, 2020 Leave a comment

Q(Question):

Hi Experts, here i come again and wanna ask how we can perform record update in PHP & MySQL without passing the id in the URL for the $_GET method to be used in the processing page. I mean I have records of tenders displayed in a page and each of the records are hyper linked to edit and delete links. And at present what i am doing is embedding id in the URL i.e

<a href=edittender.php?id=$id>Edit</a>

. Now, i dont want the id to be embedded in the URL and instead want any other methods to be applied to get this workdone. Can you all advice me how i can go about?

A(Answer):

use the POST method, though this requires either form submission or AJAX procedures.

regards

A(Answer):

thankyou but i am not sure how POST can be used in this situation. Can i have an example please?

A(Answer):

<form action="edittender.php" method="post" accept-encoding="UTF-8">
<input type="hidden" name="id" value="id_to_submit">
<input type="submit" name="send" value="send request">
</form>

A(Answer):

sorry but i think you didnt understand me. well, i please see my code below:


<?php
$q= "SELECT * FROM ".TABLE." order by field";
$result_ = $database->query($q_);
$num_rows_ = mysql_numrows($result_);
for($j=0; $j<$num_rows_; $j++) {
$id = mysql_result($result_,$j,"id");
$tender = mysql_result($result_,$j,"tender");
?>
<table>
<tr>
<td><?php echo $tender; ?></td>
<td><a href="edittender.php?id=$id">Edit</a>
</tr>
</table>
<?php
}
?>

The code above can generate all records available in a table and each of it has a EDIT link. Now what i meant to say was that i dont want the id to be passed in the URL which i have done at present. In this case i can’t use a form with buttion to pass the id for a POST method.

A(Answer):

– butts in.

Then your other option is AJAX. Although, I don’t understand your issue with using GET.

A(Answer):

@raamay

why not?

does it matter if you use a button (form) or a link (href) to trigger the edit? I could have named the button EDIT to make that clearer (but I’ve had little time, so…)

A(Answer):

To submit forms without having to click a submit button your best bet as has been said twice is AJAX. PHP will do your server side stuff but if there is a problem on the client side (eg. submittting a form in a fancy way) you want to go javascript/AJAX.

A(Answer):

@TheServant

that’s a rather complicated way of submitting a form…. and kind of spoils the intention a form.

the only thing is that you (normally) don’t leave the page with AJAX, whereas a link will make you leave the page (so does a form).

but still I’ve not been told why a form is here impossible to use. I’d really like to know that.

A(Answer):

Hi.

What I am wondering is… what is the point of removing the ID from the URL?

Whether you pass it via the URL, a typical form using POST or AJAX, the result is the same.
And from a security standpoint, they are all pretty much equal. (Given that you designed the server-side portion properly.)

A(Answer):

@Atli

you can’t bookmark it?

A(Answer):

@Dormilich

To be hones, that doesn’t seem all that important.

Presumably, the ability to update records is protected by server-side code, like a login mechanism, and is subject to server-side validation.

Simply having the link to the update page and the ID you want to update should not be enough to actually update it. You should need to pass some sort of validation, and you should need to pass valid data.

If that is no the case, there are bigger problems here then the method used to pass the ID.

A(Answer):

@raamay

I think this is due to security reasons. IMO first encrypt the id and send it via URL using GET method. In the receiving page(here edittender.php) again decrypt it an process.

I prefer to send the value via POST method, though AJAX is good but more complex than using POST or GET method.