0

Can I use php form input with if else statement

Using $_Get I'm trying to echo the value of a key if $_Get is found in the array https://code.sololearn.com/wIAFLx1Zc12Z/?ref=app

9th Feb 2020, 5:13 AM
Steven “Thebueno” Bueno
Steven “Thebueno” Bueno - avatar
6 odpowiedzi
+ 1
Steven, Use `array_key_exists` instead, this function searches for key instead of value (something that `in_array` does). if (array_key_exists($name,$people)) // code here else // code here Reference: https://www.w3schools.com/php/func_array_key_exists.asp P.S. In your code, you passed "$name" (a string) to `in_array` instead of $name (a variable - without quotes). (Edit) Array keys are case sensitive, so "james" exists, but not "James".
9th Feb 2020, 5:32 AM
Ipang
+ 2
Hello Steven, Share your code within your question Description. It would be difficult to understand exactly what you mean until there's a code for review. Please follow this guide on how to share your code link 👍 https://www.sololearn.com/post/74857/?ref=app
9th Feb 2020, 5:17 AM
Ipang
+ 1
I added the code I was talking about...its my first time asking on this forum. I'm trying to get the output to be the value of James if the form input is James but I only get the else condition when I run the code
9th Feb 2020, 5:22 AM
Steven “Thebueno” Bueno
Steven “Thebueno” Bueno - avatar
+ 1
That worked like a charm thanks so much
9th Feb 2020, 5:44 AM
Steven “Thebueno” Bueno
Steven “Thebueno” Bueno - avatar
+ 1
You're welcome Steven 👌
9th Feb 2020, 5:52 AM
Ipang
0
You could do: if (isset($_GET["asd"])) echo $_GET["asd"];
9th Feb 2020, 5:17 AM
coddy
coddy - avatar