SEC S20W3|| Introduction to PHP Part -1

in dynamicdevs-s20w3 •  6 days ago  (edited)

1000168521.png

Dear Steemians,

After two weeks of learning and discoveries about databases and SQL language, we are pleased to invite you to participate in the SEC S20W3 competition for the second week, continuing this exciting journey.

In this second part, we will educate you on PHP, another important scripting language that is crucial for your journey as a web developer. We will teach you its syntax, conditional statements, and other essential features that you will find valuable.

PHP, which stands for Hypertext Preprocessor, is a popular scripting language that runs on the server, unlike other languages that run on an editor, browser, or terminal console. This makes PHP a powerful technology because it communicates directly with the server. For this reason, it is often used to manage activities involving a database and a server. The good thing about PHP is that it can be embedded inside an HTML file, similar to how EJS allows users to run JavaScript in HTML documents.

Syntax:

Like other languages, PHP has its own syntax. PHP code must be embedded within specific tags to be processed correctly:

<?php // Your PHP code goes between these tags ?>
As with most programming and scripting languages, semicolons are used to end a line of code. This ensures both other developers and the server know the code has finished.
PHP is case-insensitive for function and object names, but variable names are case-sensitive. For example:
$variableName = "Starr"; // is different from $Variablename = "Starr";
As you can see, the two variable names perform two different actions in PHP, so you must be cautious when creating variable names. Also, variable names in PHP must start with a dollar sign ($), signaling to the PHP server that the content is a variable container. PHP supports common data types like strings, numbers, booleans, and even null values.

To print output in PHP, we use the echo command. For example:
echo "Have a good day!";

Conditional Statements

Conditional statements allow code to execute based on specific conditions. There are three commonly used conditional statements: if, else if, and switch.

If statement:

if (30 > 65) { echo "Have a good day!"; }

Elseif statement:

if (5 < 10) { echo "Good Morning!"; } elseif (5 > 20) { echo "Good Night!"; } else { echo "Good Afternoon!"; }

Switch statement:

$car = "BMW";

switch ($car) {
case "BMW":
echo "This is a BMW model";
break;
case "Toyota":
echo "This is a Toyota model";
break;
case "Rolls Royce":
echo "This is a Rolls Royce model";
break;
default:
echo "Your car model is not recognized"; }

These conditional statements are effective for solving different problems. Complex tasks requiring many conditions are best handled by the switch or else if statements, while simpler problems can be solved with a straightforward if statement.

Functions:

In PHP, functions allow the reuse of code, preventing repetition. Professional developers create functions to call them anywhere in their code to solve specific issues.

Function syntax:

function greetUser() { echo "Hello Friend!"; }

greetUser();


GET Method:

GET method retrieves data from a form or renders HTML pages. It is commonly used in web pages and search engines, but it exposes data in the URL, making it vulnerable to attacks. Therefore, it’s not recommended for handling sensitive information.


1000168333.jpg

1000168334.jpg



1000168335.jpg

1000168375.jpg


POST Method :

On the other hand, the POST method is used to send data securely to a server or database, such as passwords and sensitive information. It does not display data in the URL, making it more secure than GET for sensitive tasks.


1000168341.jpg

1000168340.jpg



1000170555.jpg

1000170556.jpg


Setting up your php server.

Step 1: Download a xamp server and an editor, I usually prefers visual studio.

Step 2: Set up your xamp and start up your server and database. Also set up your visual studio editor.


1000167542.jpg

1000167543.jpg


Step 3: Click on open folder, then look for your "xamp folder>Htdocs," then you are expected to create a new project folder and select it.

Step 4: In your editor, create a new file, learn. php then save it, after that go to your browser and type localhost/Project name /file name



1000167554.jpg

1000167362.jpg



Step 5: Go back to your visual studio to find the error in the picture below, click on the "OPEN SETTINGS" function.

Step 6: you would find an option "PHP validate Executable Path" that would link you to a New page on your visual studio.


1000167555.jpg


1000167556.jpg


Step 7: Go to your file manager, follow the directory "Xamp > PHP> the PHP application with logo."and copy the path .

Step 8: Submit It in your editor and add php.exe then save it.


1000167534.jpg


1000167585.jpg


Our output was successfully.


1000167774.jpg

1000167807.jpg


Questions


Section 1

Fill in the correct answers and please give reasonable explanation for the answers.

  1. What's the full meaning of PHP?

  2. What type of language is PHP ?

  3. What do you understand by Conditional statements?

  4. Why is functions very important in web development?

  5. Give 5 difference between GET and POST method.


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.

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.

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

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

Note: I recommend installing extensions like LIVE Server and PHP Server to improve your efficiency when developing with PHP

Contest Guidelines

Post can be written in any community or in your own blog.

Post must be #steemexclusive.

Use the following title: SEC S20W3|| Introduction to PHP Part -1

Participants must be verified and active users on the platform.

Post must be more than 350 words. (350 to 500 words)

The images used must be the author's own or free of copyright. (Don't forget to include the source.)

Participants should not use any bot voting services, do not engage in vote buying.

The participation schedule is between Monday, September 23 , 2024 at 00:00 UTC to Sunday, - September 29, 2024 at 23:59 UTC.

Community moderators would leave quality ratings of your articles and likely upvotes.

The publication can be in any language.

Plagiarism and use of AI is prohibited.

Participants must appropriately follow #club5050 or #club75 or #club100.

Use the tags #dynamicdevs-s20w3 , #country (example- #tunisia, #Nigeria) #steemexclusive.

Use the #burnsteem25 tag only if you have set the 25% payee to @null.

Post the link to your entry in the comments section of this contest post. (very important).

Invite at least 3 friends to participate in this contest.

Strive to leave valuable feedback on other people's entries.

Share your post on Twitter and drop the link as a comment on your post.

Your article must get at least 10 upvotes and 5 valid comments to count as valid in the contest, so be sure to interact with other users' entries

Rewards

SC01/SC02 would be checking on the entire 16 participating Teaching Teams and Challengers and upvoting outstanding content. Upvote is not guaranteed for all articles. Kindly take note.

At the end of the week, we would nominate the top 5 users who had performed well in the contest and would be eligible for votes from SC01/SC02.

Important Notice: The selection of the five should be based solely on the quality of their post. Number of comments is no longer a factor to be considered.


Best Regards,
Dynamic Devs Team
@kouba01

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:  

Good lesson but let down by weak presentation.

Check your grammar.
Make screenshots of code larger.

@kouba01 have you checked this post?

correct this "Use the following title: SEC S20W2 || Databases and SQL language - Part 2"

Thank you for your feedback. We will review the grammar and improve the presentation. I'll also contact @starrchris to address these points.

I'll make sure to update it as soon as possible.

Thanks boss, I have edited it. Next time I would pay more attention to my grammar and the size of images I use.

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

image.png

How I actually wish I have a laptop, I will have definitely love to participate in this educative post because I am so sure I will definitely get to learn a lot from this. This is really looking so educative and I can't wait to read though once again.

I have been hearing about PHP but only know few knowledge about it but reading this post, it tends to give me more details and information to learn and understand about php. This is quite highly educative for me I must confess

Great lesson. As a web developer, I've been using the MERN stack for my projects. I think this is an opportunity to learn php. I would like to know if im qualified to participate
@kouba01