250 likes | 353 Views
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.
E N D
ACM Web Development Workshop - PHP By Luis Torres
DON’T FORGET TO INSTALL “WAMP or MAMP SERVER” ON YOUR COMPUTERgoogle/yahoo/bing it
Click Start the services! And put online!
Localhost will open whatever is named index.html/index.php in the www directory
This folder will contain our website files, if you want to run a phpfile it has to be INSIDE of this folder
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!
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.
OMG PHP is easy :D Well.. Lets continue to the other stuff
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.
PHP $_GET • How does it works? • In the google example, they use the URL, to pass variables that will be used in that page.
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
Notice how you get the values using get. GET will always get values from the URL
But without the URL it wont work :’( • Here is how to fix that, just check if the $_GET “isset()”:
But, how can I change the values being passed without hardcoding? • We have Forms
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.
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’]
PHP Include • What if you have a multiple functions, and you don’t want to copy paste them on all your files. • Really simple:
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.
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.