You are viewing our Forum Archives. To view or take place in current topics click here.
[PHP] Echoing
Posted:

[PHP] EchoingPosted:

Download
  • Junior Member
Status: Offline
Joined: Dec 08, 201013Year Member
Posts: 72
Reputation Power: 2
Status: Offline
Joined: Dec 08, 201013Year Member
Posts: 72
Reputation Power: 2
Hi, this is a tutorial on some PHP. This will cover 3 different types of echoing,

1. Echo information on the page
2. Echo information off another page ($_POST)
3. Echo information off another page and give a custom URL ($_GET)

Now we will cover the number 1. This is an easy concept to grasp, here is an example:

[php:1:dd7315b736]
<?php
echo "<h1>I love Download</h1>";
?>
[/php:1:dd7315b736]

This simple piece of code will display "I love download" in heading 5, PHP can echo HTML too, but be careful having links included you will have to do:

<a href='#'>Hi</a>


Notice the ' instead of ", these work the same way and vice versa, if you have 2 sets of " they will clash giving you an unexpected result, and most likely not a good one. You can also echo "strings" like this

[php:1:dd7315b736]
<?php
$string = "PHP is amazing";
echo $string;
?>
[/php:1:dd7315b736]

Now this will produce a line in HTML saying "PHP is amazing". Very simple, on to number 2.

$_POST
This command basically just grabs information from a form, and well posts it, hence the name $_POST. This is another easy situation that I will post an example:

Form.html (File Name)

<form action="you.php" method="post">
Name: <input type="text" name="firstname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>


This will submit information into a form called "you.php", now to retrieve the info.

you.php (File name)
[php:1:dd7315b736]
Hi <?php echo $_POST["firstname"]; ?>!<br />
Only <?php echo $_POST["age"]; ?> years old?
[/php:1:dd7315b736]

What this does is retrieve information from the text box named "firstname" the displays it on you.php, and same thing with age except with different variables. Now this will only take you to a URL like this [ Register or Signin to view external links. ] and if the user wants to see his or her information, they must fill out the form each time, and this is where $_GET comes in handy.

$_GET
To explain this function we will use the same variables as $_POST, but $_GET does all the same stuff as $_POST and more... It displays the information in the URL so a user can go back to an already filled out form and see the exact same information.

Form.html (File name)

<form action="you.php" method="get">
Name: <input type="text" name="firstname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>


As you can see, the exact same form as before, except for the method, so all as we do is replace the method with get. Now to get the information.

you.php (File name)
[php:1:dd7315b736]
Hi <?php echo $_GET["firstname"]; ?>.<br />
Only <?php echo $_GET["age"]; ?> years old?
[/php:1:dd7315b736]

Now were getting the same variables, but in a different way, so basically the url will look like this now: [ Register or Signin to view external links. ] . The user now has access to go back and see his filled out form, hope this tutorial helped.
#2. Posted:
xNZxAssAssiNx
  • Resident Elite
Status: Offline
Joined: Dec 14, 201013Year Member
Posts: 283
Reputation Power: 11
Status: Offline
Joined: Dec 14, 201013Year Member
Posts: 283
Reputation Power: 11
Only skimmed through (i already know how to) but these seems a good tutorial for people wanting to know a little php
#3. Posted:
WaterBottle
  • TTG Senior
Status: Offline
Joined: Oct 24, 201014Year Member
Posts: 1,265
Reputation Power: 54
Status: Offline
Joined: Oct 24, 201014Year Member
Posts: 1,265
Reputation Power: 54
you lost me
wtf did you just copy and paste ?
#4. Posted:
Download
  • Junior Member
Status: Offline
Joined: Dec 08, 201013Year Member
Posts: 72
Reputation Power: 2
Status: Offline
Joined: Dec 08, 201013Year Member
Posts: 72
Reputation Power: 2
I created this tutorial myself.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.