SEC S20W3|| Introduction to PHP Part -1

Hello Steemians, welcome to my post, and stay safe as you read through this post.

1000183550.png
Canvas


What's the full meaning of PHP?

The full meaning of PHP is Hypertext Preprocessor. Personal Home Page is what it originally stood for but as its functionality has increased the name has changed to reflect how it is been used as a server-side scripting language that is designed for the development of websites.


What type of language is PHP?

PHP is known as a server-side scripting language which is used for web development. PHP is embedded in HTML and also it is designed to manage databases, dynamic content, and session tracking which can also be used to build an e-commerce website. Also, PHP is a loosely typed, interpreted language, which means it does not need an explicit declaration of data type as it executes data at runtime.


What do you understand by Conditional statements?

What I understand by Conditional Statements is that they are programming constructs that allow the execution of different blocks of code based on whether a specified set of conditions is evaluated to be false or true. They are for decision-making within programs which allow a program to take different actions based on how the situation is. if statement, if-else statement,switch/case statement, andelse-if (elif in Python)` are the common types of conditional statements that I am familiar with.


Why are functions very important in web development?

Functions are very important in web development for the few reasons given below.

  • Code Reusability:
    Functions allow developers to write a piece of code once and reuse it multiple (many) times throughout a program, which reduces redundancy. For example, instead of writing the same block of code to validate forms on different pages, I can write a validation function and call the function at the place it is needed.

  • Readability:
    Functions help us to improve code readability by removing away complex tasks into simply named blocks of code. Now for example, instead of me cluttering my main program with extensive logic, I can encapsulate the logic inside the functions so the code can me more easier for me to follow it up and understand it better.

  • Modularity: Functions allow us to break a large, complex problem (issue) into smaller parts. This approach makes code easier to maintain, test, and understand as each function can handle a specific task.

  • Debugging and Testing:
    Functions can individually be tested, which makes debugging easier. By leaving one issue within functions, we can test each one separately to ensure it works perfectly.

  • Maintainability:
    By using functions it improves code maintainability. For example, if there is a certain functionality that needs to be updated, we only need to modify the function in one place, instead of tracking down all occurrences of the same code one after another throughout the project. This simply means functions reduce errors and save time during feature updates or debugging.


Give 5 differences between the GET and POST methods.

Here I have highlighted 5 differences between the GET and POST methods in a tabular form for easy understanding.

Key differenceGETPOST
Data VisibilityAppends data to the URL, which makes it visible in the address barSend data in the request body, which keeps it hidden from the URL
Data LengthIt is limited by URL length which the restriction is varies by browser with about 2048 characters.There is no significant size limit, as it depends on server configuration, which allows the transmission of large data.
CachingRequests can be cached by browsers and stored in a browser historyRequests aren't cached and stored in a browser history
Use caseIt is used for retrieving dataIt is used for submitting data.
SecurityIt is less secure as data is exposed in the URLIt is more secure since data is not visiting the URL

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.

Here I use conditional statements to check if a user inputs an even number, or an odd number and print the corresponding numbers which I run the code via One Compiler

# Get user input
user_input = int(input("Enter a number: "))

# Check if the input is even or odd
if user_input % 2 == 0:
    # If even, print even numbers from 0 to 30
    print("Even numbers from 0 to 30:")
    for i in range(0, 31):
        if i % 2 == 0:
            print(i)
Else:
    # If odd, print odd numbers from 0 to 30
    print("Odd numbers from 0 to 30:")
    for i in range(0, 31):
        if i % 2 != 0:
            print(i)

Code and Output

1000183517.jpg

Odd Numbers: 5

Output

1000183524.jpg

Even Numbers: 10

  • The code asks the user for a number to input and if.

  • The number is odd (5), all odd numbers from 0 to 30 will print.

  • Of the numbers even (10), all even numbers from 0 to 30 will print.


2• Create a form that accepts sign-up data, and sends 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.

Here I have created two separate forms using one compiler. The first form captures the username and email and sends them to user.php using the Post method.

Form 1: Send username and Email to user.php

Output/Result

1000183496.jpg

The left is the code, whereas the right is the output.

Form 2: Post Password and Age to secure.php

Here in this form, the user password and age will be captured and sent to secure.php using the Post method.

Output/Result

1000183512.jpg

The left is the code, whereas the right is the output.


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

Here is a Python function that greets the user by saying to the users "hello" when they register an account.

def register_account():
    # Ask the user to input their username
    username = input("Enter your username to register: ")
    
    # Call the function to greet the user after registration
    say_hello(username)

def say_hello(username):
    # Function that says hello to the user
    print(f"Hello, {username}! Welcome to our platform.")

# Call the register_account function to simulate user registration
register_account()

Code/Output

1000183535.jpg

  • The register_account() function is what prompts the user to input their username.

  • Once a user has input his or her username, the function say-hello(username) is called.

  • It is the say-hello() function that prints a greeting message that includes the username.


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

Here I created a simple and beautiful-looking sign and Login design with a combination of HTML, CSS, and Bootstrap for beautiful representation you can see the code on the left-hand side and the output on the right-hand side as shared below.

1000183543.jpg

I am inviting: @pelon53, @dove11, and @simonnwigwe,

Cc:-
@starrchris

Sort:  
Loading...

Your post has been rewarded by the Seven Team.

Support partner witnesses

@seven.wit
@cotina
@xpilar.witness

We are the hope!

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.