0

INPUT VALUE TO USE IN IF STATEMENTS IN PHP

How can I use the value received from the user by input box in if . For example :I received a user input of "Alex" Now I want to use the Alex in if statement so that the if statement will only execute or echo it is true when the user input is <?php $value = $_POST["user"]; If($value==Alex){ Echo ("yes"); } Else { Echo("no"); } So is it right ,whenever I run this ok local host it show error of Alex value Can anyone help me with this I'm a beginner.

27th Nov 2018, 5:44 PM
Acash
3 Answers
+ 2
// Write if($value == "Alex") Because Alex is string so we have to write it between " " or '.' ; Or //$username ="Alex" ; if($value == $username) Here we already put a value to $username with "Alex"
27th Nov 2018, 5:57 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
Whenever you're working with a string in an if statement you should put it inside quotation marks.
27th Nov 2018, 5:55 PM
Yordan Hristov
Yordan Hristov - avatar
0
Change the if statement to this: if($value=="Alex")
27th Nov 2018, 5:53 PM
Yordan Hristov
Yordan Hristov - avatar