1 / 25

ACM Web Development Workshop - PHP

ACM Web Development Workshop - PHP. By Luis Torres. DON’T FORGET TO INSTALL “WAMP or MAMP SERVER” ON YOUR COMPUTER google /yahoo/ bing it . Running wamp :. Click Start the services!. And put online!. Localhost will open whatever is named index.html/ index.php in the www directory.

ely
Download Presentation

ACM Web Development Workshop - PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ACM Web Development Workshop - PHP By Luis Torres

  2. DON’T FORGET TO INSTALL “WAMP or MAMP SERVER” ON YOUR COMPUTERgoogle/yahoo/bing it 

  3. Running wamp:

  4. Click Start the services! And put online!

  5. Localhost will open whatever is named index.html/index.php in the www directory

  6. This folder will contain our website files, if you want to run a phpfile it has to be INSIDE of this folder

  7. This is how the www folder will look like.(more or less)

  8. Open “index.php”, erase all its content and replace with the following BE CAREFUL: This is the concatenation character in PHP. In java is the “+” character. Don’t confuse them!

  9. Different approaches to code in php

  10. Lets do functions! Our function doMath will take two inputs, and compute its sum. Since we are not declaring types, we ASSUME that the inputs will be integers. Inside the function we could check the types if we wanted to make sure that everything is ok.

  11. OMG PHP is easy :D Well.. Lets continue to the other stuff

  12. PHP $_GET • Purpose: Sometimes we want the same page to have a function that can do multiple outputs based on the input. • Ex: google search will work the same way, but will yield different outcomes.

  13. PHP $_GET • How does it works? • In the google example, they use the URL, to pass variables that will be used in that page.

  14. Wait… What? • Lets go back to the doMath function. • For the purpose of teaching, lets assume you have this URL: (you hard code the rest of the url) • Lets break it down:localhost/yourFile.php <- this is your file • ? Question mark shows where variables begin • variableA <- the variable “varaibleA” has a value of 2 • & <- this character concatenates multiple variables • variableB<- the variable “varaibleB” has a value of 3

  15. Notice how you get the values using get. GET will always get values from the URL

  16. But without the URL it wont work :’( • Here is how to fix that, just check if the $_GET “isset()”:

  17. Now it works for both 

  18. But, how can I change the values being passed without hardcoding?  • We have Forms

  19. How does it work? Will be obtained in yourFile.php using $_GET[‘variableName’] Input type submit is a button, after clicking the button it will go to the specified file, with the specified values and execute.

  20. What if I want to be mysterious and not show anything in the URL? • You can use the POST function • Similar to $_GET[‘variable’], you use $_POST[‘variable’]

  21. Are they different?

  22. PHP Include • What if you have a multiple functions, and you don’t want to copy paste them on all your files. • Really simple:

  23. PHP Include • WONT WORK if you put the include after you method call. • Make sure all your includes are at the top of your code if possible.

  24. Ermm we got this far..? • We are missing: • forms with PHP (dynamic forms) • Sessions • SQL/databases • Javascript • Ajax • So basically another workshop  or 2..or more.

More Related