PHP · 4 min read · Nov 16, 2025
Принятие решений с использованием IF-ELSE в PHP
Принятие решений с использованием IF-ELSE в PHP
Дорогие студенты,
today we are going to study the tools that will help you to write Decision Making Codes in php. For example, when you sign in to orkut.com you see a message ‘hello username’ on the upper right of every page. Similarly when you login to gmail if you provide wrong username or password you see an error message and if you submit accurate information you are taken to the inbox.
If you think deep on these events, this is what we call ‘decision making code’. your write intelligent code that can make decision on user’s input and can act accordingly to the input to produce required output.
PHP provides us IF - ELSE statements to write decision-making-code. Suppose I want to make a page that asks for the user’s name and password and if the username and password are wrong it displays welcome message otherwise unauthorization message.
There could be different ways to do it,
- to read the username and password from xml file (wow! I like that!)
- to read the username and password from text file (faster than database)
- to read the username and password from MySQL database (or Oracle, PGSQL, MySQLi, Access)
- to read the username and password from Excel sheets (advance)
- Stupid way
Guess what I am going to follow? … well, method 5 … and the only reason is that you have not learnt the rest of the four methods till now therefore I have no other choice but to do it the stupid way to give you a broad understanding of IF-ELSE statements.
I am going to hardcode username and password and then check it through IF-ELSE. Let’s do it!
Синтаксис IF-ELSE:
The basic IF-ELSE syntax is as follows,
if(condition) {
//block of code
}
else {
//block of code
}
If the condition that we knit together by the help of logical and comparison operators if found true then the code between IF braces will be executed otherwise ELSE code block will be taken on.
Following is the html code to get input from user.
Now let’s write the check.php code with IF - ELSEGet new posts in your inbox
No spam. Unsubscribe anytime.