php - Accessing $_POST variables cause errors -
I was wondering if you could help me with the following:
A form on the next page. I am using the $ _ POST
method. Although the information is visible in the browser, when checking the code shows an notification: the undefined index error and the value of that value There is no mark where it should be (in the code). I think it is related to the above error.
The way I am calling it is for the former:
$ name = $ _POST ['name']; Besides this, I am trying to get the same information in a hidden area so that to store them in a database (after viewing the page) here but here no one Even the values could not be passed. The value in the hidden is empty. Sorry if this is a silly thing ... but at stake and I do not know what I'm doing is wrong. Thank you very much for any help. Francisco
In PHP you can not read the variable which Does not exist. For non-existing simplified variables such as $ foo
or $ bar
you will get an unchanging variable notice, such as non-current array index such as $ Array ['foo']
or $ array ['bar']
gives you an undefined index notice and non-current object properties such as $ item - & gt; Foo
or $ object-> Bar
you will notice undefined properties
The reason for this is that PHP variables should be declared before reading-entry can be done. The function in PHP is to test if a variable exists, for array and for object properties. Apart from this, isset
is a universal tool for testing the existence. (Note that the value null is not equal to current.)
So in your case, you should check that if $ _ POST ['name']
Exists before trying to read it:
if (array_key_exists ($ _ POST, 'name')) {$ name = $ _POST ['name']; } // if (isset ($ _ POST ['name']) {$ name = $ _POST ['name'];}
but note that the $ name
now depends on the existence of $ _ POST ['name']
.
Comments
Post a Comment