Question:
PHP $_GET variable is throwing me an error?
jnbill1204
2008-04-16 20:40:19 UTC
I have an input box that looks like this


I am trying to retrieve that value with

echo $_GET['keywords[like]'];

but it keeps throwing an error
Notice: Undefined index: keywords[like]

what can I do about this?
Three answers:
Josiah
2008-04-16 23:49:33 UTC
You get the error because your php processes the keywords[like] name as a multidimensional array.



so to access the get variable you need:



echo $_GET['keywords']['like'];
B7x0
2008-04-17 03:56:48 UTC
I think you get the error because:



Since you are using $_GET method, you have to put that method in the form. Such as:















Edit:

Something else I forgot to mention. When your passing an array from your form fields, you can't catch it like that:

$_GET['keywords[like]'];



PHP knows that's an array, so you have to pass it like:

$_GET['keywords'][like];



and so on.



To catbertnc:

I'm pretty sure that "id" is only used for styling purposes [ie. CSS] it doesn't pass anything to the GET/POST methods, so you have to use the "name" attribute.



B7x0
catbertnc
2008-04-17 04:04:46 UTC
Try this.





Then echo $_GET['keywords-like'];



I believe $_GET bases the info on the tag's ID, not the name. Also, the brackets in the id and name may cause issues.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...