I've got a handle on MySQL and HTML, but am still learning PHP. I'm on a bit of a schedule, so when I noticed that Dreamweaver would write PHP for me I started using that feature. I immediately noticed that, of course, the code it inserts isn't that great.
When investigating "Notice: Undefined index:" I came across PHP error: Notice: Undefined index:.
DeaconDesperado pointed out that alibenmessaoud's code was trying to process before post values were set. So I looked into my code for the same problem and noticed that Dreamweaver is using
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "name_of_your_submit_input"))
instead of
if(isset($_POST) && array_key_exists('name_of_your_submit_input',$_POST))
Am I misunderstanding Dreamweaver's code? Isn't checking if the post is the submit name the same as checking if it exists? Am I misunderstanding array_key_exists()? Last question, does it matter that my check is above the form itself?
Thanks for putting up with a newbie who hasn't finished the w3schools PHP tutorial yet.
$_POST
is set.. So even if the input ofMM_insert
is not set, but another post is forwarded.. Your script will continue to the second param, it's better to stop it at the first check rather than latter – Astrographisset($_POST)
is .... catching a very, very rare edge-case... That is just as easily handled withisset($_POST["MM_insert"])
. (it is checking whether the superglobal $_POST exists, which will only not exist if variables_order does not includeP
, which you will probably never encounter in your lifetime. The OP there probably believed it wasn't set on GET requests. Trust me, it is. Andisset($_POST["MM_insert"])
catches it as well. – Percussive