
-----------------------------------
octopi
Sun Jun 01, 2003 12:31 am

[Tutorial] Very Basic
-----------------------------------
Basic Tutorial

The most basic php program




To print data, you can use either the print, echo, or header function.
Header is used to output headers to the browser.

  header("Content-type: text/html\n\n");

Print and echo are used to output data.

  print ("text");
  print "text";
  echo "text";


Varibles:

$name="Name";
echo "$name";
//outputs: 'Name'

Getting data from the user:
There are two methods to get data from the user, GET, and POST
When someone accesses your program like this

program.php?name=SOMETHING

That is using the GET method.

When someone uses a form it can either be in GET, or POST


...

OR

...



To access these varibles you can do:
$name=$_GET['name']; //or
$name=$_POST['name'];
or this:
($name=$_GET['name']) || ($name=$_POST['name']);

the above will get the GET, and POST methods (usually there is only one method used at a time, so it shouldn't be a problem)


Conditionals:

if($name) {    //if name has a value
  echo "stuff here";
}

if(!$name) {     //if name doesn't exist
  echo "stuff here";
}


if($name == "octopi") {
  echo "stuff here";
}


if($name == $somethingelse) {
  echo "stuff here";
}
elseif ($name == $myotherthing) {
  echo "check this if the above fails";
}
else {
  echo "something else";
}
