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 pos开发者_运维问答t, 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 :)
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.
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
精彩评论