SEC S20W3|| Introduction to PHP Part -1

in dynamicdevs-s20w3 •  2 months ago  (edited)

steemit-engagement-challenge-cover.jpeg

Greetings Steemit friends

What's the full meaning of PHP?

PHP: Hypertext Preprocessor.

What type of language is PHP?

PHP is a server-side scripting language most used for web development. It is an open-source language easily embedded in HTML to create dynamic web pages. It is best for building a data-driven website, with the ability to connect to databases (MySQL, PostgreSQL, and SQLite). PHP is the most widely used language for web applications. PHP relies on its versatility, which makes it possible to run across various platforms.

PHP gives developers the flexibility to build scalable applications using frameworks like Laravel. It is the language used at the back end for CMS like Drupal, WordPress, and Joomla.

PHP versatility enables the language to handle different data types, supporting REST APIs, etc. PHP has an inbuilt function for handling security features like data encryption, sessions, SQL injections, etc.

To conclude, the language is a server-side script. Its function is to move data between the server, which holds the databases, and send it to the browser.

What do you understand by Conditional statements?

Conditional statements help in displaying different blocks of code, by checking if a condition is made. Conditions statements are used to perform actions based on the condition while controlling the flow of data. There are four types IF, if-else, if-else if-else, and switch.

  • If:

This is the most common and simplest used conditional statement. It is used to check if a condition is true. Here the if statement does not border on false condition. Its main objective is to make sure that the condition is true.

$username = fombae;
if ($username = fombae) {
echo "Mr Bull.";
}

  • If-else:

This is an upgrade of the If statement we just looked at above. Here we have a one more step condition to check if a condition is false. The else section was added to make it possible to check the true and false.

$username = fombae;
if ($username = fombae) {
echo "Mr. Bull.";
} else {
echo "You are Not Mr Bull";
}

Note: only the developer making use of this condition can determine which block will tell if a condition is true or false.

  • if-elseif-else:

This is one more step added to the if-else statement. The else if the conditional statement is used to add multiple checks for different conditions which will return true.

$username = fombae;
if ($username = fombae) {
echo "Mr Bull";
} elseif ($username = mr_bull) {
echo "Mr Bull";
} elseif ($username = fomba) {
echo "Mr Bull";
} else {
echo "You are Not Mr Bull";
}

  • Switch :

This is another way of performing an if-else statement. It is best for situations with multiple else-if conditions.

$username = "fombae";
switch ($username) {
case "fombae":
echo "Mr Bull";
break;
case "mr_bull":
echo "Mr Bull";
break;
default:
echo "You are Not Mr Bull";
}

Why are functions very important in web development?

Functions are important in web development in lots of aspects, I hope I will be able to remember them all to outline them. Developing a web project will mean you are working with a language and in our case PHP. To have a well-structured, efficient, and scalable project. We need to make use of functions.

Functions help us not to repeat the same line of code, which will output the same result. Functions reduce redundancy in code, and the same save time.

function getUserSteemPower($username, $steempd) {
return $username .' SP '. $steempd;
}

Screenshot 2024-09-24 101413.jpg

Screenshot 2024-09-24 101434.jpg

Functions make it easy for testing and debugging during web development. Functions make it easy to find bugs, and fixing them will solve the problem in every section where the function is called.

Function is a tool for factorization. Following the rule of a function, which is expected to do one thing and one thing only. The function helps in breaking tasks during web development.

Functions can be used to hide complex logic in web development. It is two ways, as we can use functions to break complex logic. This is common when we use functions within a function.

Functions help to work on web projects without breaking code. All you need to do is create a new function to add a new feature.

Give 5 differences between the GET and POST methods.

  • The GET method data is visible on the url while the POST method is hidden in the url.
  • The GET method is used to get data while the POST method is used to send data
  • The GET method security level is low given that the data is exposed on the URL, while the POST method is more secure.
  • The GET method data is stored in the browser history while the POST method is not stored in the browser history.
  • The GET method can handle only ASCII data type while the POST method can handle different data types.
  • The GET method has a limitation of data length to handle while the POST method can handle large amounts of data.

Section 2

1• Using a conditional statement, print even numbers from 0 to 30 if a user inputs an even number, otherwise print odd numbers if the user inputs an odd number.

Let make use of the if else statement.

Screenshot 2024-09-23 185633-1-a.jpg

User Input 2(even Number)

Screenshot 2024-09-23 185633-1-b.jpg

Screenshot 2024-09-23 185633-1-c.jpg

User Input 5 (odd Number)

Screenshot 2024-09-23 185633-1-d.jpg

2• Create a form that accepts sign-up data, and send the username and email to a new page named user.php.

Create a form that posts the password and age to a new page named secure.php.

  • Get

Screenshot 2024-09-23 193248-2-a.jpg

Screenshot 2024-09-23 193248-2-b.jpg

Screenshot 2024-09-23 193248-2-c.jpg

Screenshot 2024-09-23 193248-2-d.jpg

  • Post

Screenshot 2024-09-23 195500-22-a.jpg

Screenshot 2024-09-23 195500-22-b.jpg

Screenshot 2024-09-23 195500-22-c.jpg

Screenshot 2024-09-23 195500-22-d.jpg

3• Create a function that says "hello" to the user when they register their account.

function sayHello($userNames){
if (!empty($userNames)) {
# code...
echo 'Hello ' . $userNames;
} else {
# code...
echo 'Check your Username';
}
}

Screenshot 2024-09-23 201638-3a.jpg

Screenshot 2024-09-23 201638-3aa.jpg

Screenshot 2024-09-23 201638-3b.jpg

Screenshot 2024-09-23 201638-3c.jpg

4• Create a beautiful sign-up and login page, which will be used in the next class.

  • Sign up

Screenshot 2024-09-24 074216-4-a.jpg

Screenshot 2024-09-24 074216-4-aa.jpg

Screenshot 2024-09-24 074216-4-aaa.jpg

Login

Screenshot 2024-09-24 074216-4-b.jpg

Screenshot 2024-09-24 074216-4-bb.jpg



Cheers
Thanks for dropping by
@fombae

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...

Upvoted! Thank you for supporting witness @jswit.

You have explained all the tasks with the details of the code. All of your outputs are working fine. PHP language is really very useful for the dynamic web development.

SEC S20W2 || Databases and SQL language - Part 2

You forgot to add the correct title:

SEC S20W3|| Introduction to PHP Part -1

Oh, thanks @mohammadfaisal

My pleasure

This post has been upvoted/supported by Team 7 via @philhughes. Our team supports content that adds to the community.

image.png