I’m new to php and mysql. Im following a tutorial from phpacademy on youtube. There is a section that is of form data, but everyone who followed the tutorial (myself included) got undefined index errors. I fixed it with & (ampersand) symbol. But what does it do in the follow circumstances?? Why does putting the & symbol in front of the $ stop the error? Is it the same as @ and is it just suppressing the error or did it actually fix it?
$submit = &$_POST['submit'];
It means instead of assigning the value to
$submit, assign a reference to the value to$submit.If you are familiar with C and pointers, it is like a pointer to the value that is automatically dereferenced when you access it. However, PHP doesn’t allow things pointer arithmetic or getting the actual memory address (unlike C).
CodePad.
To stop the error you mentioned, you can use a pattern such as…
…or…