tags:

views:

60

answers:

2

Okay, for all my coding so far I been using GETs and only $_POST on the same script.

Ex: profile.php would show all the posts an user made and under each of their post, they can edit their post. The way I been using it is through $_GETs. So..

    //this is the link users click to edit their post
    echo '<td><a href="editad.php?posting_id='.$row3['posting_id'].' ">Edit</a>';

//on the editad.php
$posting_id=$_GET['posting_id'];
if (isset($posting_id)){
   //show all the forms, sqls to do the editing
}
else{ //if the $_GET hasn't been set
   echo "You have not specified which ad to edit. Please go back";
}

How do I do this via POST? Thanks :)

+3  A: 

The browser will submit a POST request when the HTML <form> element contains method="POST". You do not need to do anything special on the PHP end.

<form action="index.php" method="POST"><input type="text" name="blue"></form>

When submitted, PHP will see a variable $_POST['blue'] with the content of whatever was in the text that was submitted.

That said, take heed. In the first line of the code you give, you should stick with the message ID in the URL because that is GET, which you should use when no change is made to the data.

Also, since I saw your other question, let me just remind you to make sure that you check that the user has the permission to see that page. For example, search engines will crawl GET pages, but not POST.

Finally, there is no way to force the browser to use POST without it being specified AFAIK, so there's no way to do it in pure PHP.

waiwai933
Gotcha! Thank you. I was trying to see if I could use POST as to the "GET" way and guess you can't. Guess I got to stick with GET.
ggfan
@ggfan: The rule of thumb is: If a file or the database is going to be edited in any way (deleted, modified, created), use POST. Otherwise use GET.
waiwai933
A: 

Usually you use POST variables through html forms.

You cannot use POST variables in links, however. By using post variables, the variables get submitted behind the scenes.

Explaining the functionality of post variables, especially if you haven't been introduced to it before can be tedious, so I'm going to point you to a few links:

Explaining $_POST: http://w3schools.com/php/php_post.asp

A tutorial explaining the difference between $_POST and $_GET http://www.tizag.com/phpT/postget.php

arnorhs