Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tutorial] Very Basic
Index -> Programming, PHP -> PHP Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
octopi




PostPosted: Sun Jun 01, 2003 12:31 am   Post subject: [Tutorial] Very Basic

Basic Tutorial

The most basic php program

code:
<?php
  header("Content-type: text/html\n\n");
  echo "Text";
?>



To print data, you can use either the print, echo, or header function.
Header is used to output headers to the browser.

code:
header("Content-type: text/html\n\n");


Print and echo are used to output data.

code:
  print ("text");
  print "text";
  echo "text";



Varibles:

code:
$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

code:
<form method="GET">
...
</form>

OR
code:
<form method="POST">
...
</form>



To access these varibles you can do:
code:
$name=$_GET['name']; //or
$name=$_POST['name'];

or this:
code:
($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:

code:
if($name) {    //if name has a value
  echo "stuff here";
}


code:
if(!$name) {     //if name doesn't exist
  echo "stuff here";
}



code:
if($name == "octopi") {
  echo "stuff here";
}



code:
if($name == $somethingelse) {
  echo "stuff here";
}
elseif ($name == $myotherthing) {
  echo "check this if the above fails";
}
else {
  echo "something else";
}
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, PHP -> PHP Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: