BASIC Php tutorial...how is it? do you want to add to it?

This is a discussion on "BASIC Php tutorial...how is it? do you want to add to it?" within the PHP Forum section. This forum, and the thread "BASIC Php tutorial...how is it? do you want to add to it? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 20th, 2006, 18:32
Junior Member
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
BASIC Php tutorial...how is it? do you want to add to it?

I made this tutorial for a site I am making and am posting it for three reasons.
------------------
1)Beginners can use it.
2)To ask what you think of it and where I can improve.
3)To give you a chance to add to it if you want.

Code: Select all
 To start a php block of code use this
-------------
<?php 
insert code here
?>


To write a phrase:
---------------------
<?php
echo "your phrase here";
print("this also works")
?>


In php variables start with "$" minus the quotations. To assign a variable data use the "=" sign. An example would be:
------------------------
<?php
$name="John";
?>


Addtion (+), Subtraction (-), Multiplication (*), Division(/) opperators look just like that. Other opperators include "&&" for and, || for or, == for equal to. Here is how you use them:
------------------------
<?php
$num1="1";
$num2="2";
echo "$num1 + $num2";
echo "$num1 / $num2";
?>


Now for those other operators, you use them in if/else statements:
----------------------------
<?php
if (statement) {
what happens if it is true
}
else{
what happens if it isnt
}
?>

Here it is in use
-------------------------
<?php
if (5==5){
echo "yay";
}
else{
echo "what?"
}


Loops in php can be used for various things, here is the basic setup for a for loop.
--------------------------
for(initial value;comparison;incriment){
what happens
}

An example is this:
------------------------------
for($views_on_page=0;$views_on_page>10;$views_on_page+1){
echo "we need more members";
}

What that did is set the variable $views_on_page equal to zero then it setup a loop that for every time the variable was not greater than 10 it printed we need more members. After it did this it added 1 to the variable.


Functions are units that combine code. Here is the basic setup:
-------------------------
function function_name (statement, statement2){
coding;
}
function_name()

Here it is in use:
--------------------------
function add_numbers($num1,$num2){
$num1 + $num2 = $answer;
echo "$answer";
}
add_numbers(1,5)

What the first line did was create a function called "add_numbers" with the statements "num1" and "num2". On the second line it says that num1 plus num2 equal answer. Then it prints the answer. To call or use the function you use the last line of code. In the parenthesis it give the value of num1 number 1 and num2 number 5. Then it will print the number 6.


Getting Data from a user is easy but you need to know everything above and some html. So start off a form in html as follows:
---------------------------------
<form name="f1" action="math.php" method="POST">
<input type="text" name="value_one" value="number1"><br />
<input type="text" name="value_two" value="number1"><br />
<input type="radio" name="operation" value="add"><br />
<input type="radio" name="operation" value="subtract"><br />
</form>

What that did is make a form with two text boxes and two radio buttons. One says add and the other subtract.

Now for the php file called math.php:
------------------------------------
<?php
if ($_POST[operation] == "add"){
$answer = $_POST[value_one] + $_POST[value_two];
}
else{
$answer = $_POST[value_one] + $_POST[value_two];
}
echo "$answer"; 
?>

$_POST is a way of getting the data from the other file. In the second line it is seeing if the radio button set called "operation" was equal to add. In the third line it is setting the variable answer to value_one plus value_two from the other forum. Otherwise it is subtracting the values. In the second last line it is printing the answer. 



Good Job....now you know basic PHP
Reply With Quote

  #2 (permalink)  
Old Apr 20th, 2006, 20:23
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: BASIC Php tutorial...how is it? do you want to add to it?

We already have one of these in our article section:-
http://articles.webforumz.com/php/php-basics

and more here:-
http://articles.webforumz.com/php
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #3 (permalink)  
Old Apr 20th, 2006, 20:39
Junior Member
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: BASIC Php tutorial...how is it? do you want to add to it?

sorry i didnt know that
Reply With Quote
  #4 (permalink)  
Old Apr 21st, 2006, 19:54
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: BASIC Php tutorial...how is it? do you want to add to it?

No worries.... just thought they may help you write yours..
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
Reply

Tags
basic, php, tutorialhow, add

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a 3D tutorial thresherpirate Starting Out 2 Jul 2nd, 2007 11:56
need a pop up tutorial Joolsd186 JavaScript Forum 5 Aug 16th, 2006 17:00


All times are GMT. The time now is 05:35.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43