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
6 Réponses
+ 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".
+ 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
+ 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
+ 1
That worked like a charm thanks so much
+ 1
You're welcome Steven 👌
0
You could do:
if (isset($_GET["asd"])) echo $_GET["asd"];