Hello to all,
I’m reading this book and I love it. In the opening pages of the text it says that I can ask for clarifications in this forum. I understand very well all the code in Chapter 9, but I can not understand when I have to use $ _GET and when I have to use $ _POST. In particular, the example that sent me into the crisis is this:
Model A - file number 1
Code B - file number 2
($action = 'editform';)
<form action="?<?php htmlout($action); ?>" method="post">
1) If the method is of type “post” because I have to use “get”?
2) Why if I use “$_POST” the program stops working?
Well this all seems a little silly but what is happening is correct. Any input fields contained in this form will be accessed by POST but the GET value that is defined in the form action is also sent on posting the form. Anytime you have a ? starting in the action line followed by a word, this word becomes a GET KEY and if this word had an equal sign followed by a value, this value could also be referenced by GET.
<form action="?editform" method="post">
in the URL would be the current page for example page.php?editform and GET[‘editform’] has no value but isset so it could be used to trigger an action. If “the word” editform had a value, e.g. editform=process then GET[‘editform’] would have the value ‘process’.
Still, the form has method=“post” so like I said, any input names will be sent via POST and can be accessed by the input name, e.g. $_POST[‘firstname’].
Personally I think it is best to NOT define an action if posting to the same page. e.g. action=“” method=“post”
Ok, I thank you very much for your help.