Translated by Google Translate

PHP for Beginners, Fast and Simple Learning



To start learning PHP, you should have basic knowladge of HTML. There are 2 ways to create PHP file, which embadded script and non embadded script. Embadded script is PHP that placed in HTML script. While non embadded script is PHP script wrote without placed in HTML script. Here's the difference between embadded script and non embadded script when displaying string using echo command.

Embedded Script
<html>
<head>
<title>WebDev777.COM - Web Development Research and Tutorial</title>
</head>
<body>
<?php 
echo "WebDev777.COM - Web Development Research and Tutorial"
?>
</body>
</html>

Non Embadded Script
<?php 
echo "WebDev777.COM - Web Development Research and Tutorial"
?>

Or
<?php
echo "<html>";
echo "<head>";
echo "<title>";
echo "WebDev777.COM - Web Development Research and Tutorial";
echo "</title>";
echo "</head>"; echo "<body>";
echo "WebDev777.COM - Web Development Research and Tutorial";
echo "</body>";
echo "</html>";
?>

Or
<html>
<head>
<title>WebDev777.COM - Web Development Research and Tutorial</title>
</head>
<body>
</body>
</html>

<?php
echo "WebDev777.COM - Web Development Research and Tutorial"
?>

Explanation
In embedded script, the code placed in anywhere in html script, whereas non embedded script is php script wihout html.

After knowing how to create php file, now we go to the main lesson, how to send data via POST and GET parameters. PHP has 2 method that can be used for send data from client (browser) to the server, and that they are, POST and GET.

POST method is used to transmit data from client to server where the data will sent via http header. For an example we create an input form with name forminput.php. The script is below :

<html>
<head>
<title>WebDev777.COM - Web Development Research and Tutorial</title>
</head>
<body>
<form section method="POST" action="tInput.php">
Title : <input type="text" name="title"> <br>
Editor : <input type="text" name="editor"> <br>
Publisher : <input type="text" name="publisher"> <br>
<input type="submit" value="Submit">
</form>
</body>
</html>

And this is the forms looks in browser
Picture 1. forminput.php
The script with red color using the post method to transmit data of title, editor, and publisher to tinput.php. (action = destination) that will using $_POST command to get the data sent. Because the parameters will be sent to tinput.php then we must create tinput.php.

tinput.php
<?php
$title = $_POST['title'];
$editor = $_POST['editor'];
$publisher = $_POST['publisher'];
echo "Title : <b>$title</b> <br>";
echo "Editor : <b>$editor</b> <br>";
echo "Publisher : <b>$publisher</b> <br>";
?>
 That red script used to get data that sent by client. And this is the script above looks in browser :
Picture 2 tinput.php
GET method that works with $_GET funcion will send data or communicate via parameter that wll be visible in the URL. For more detail, change the script in the forminput.php from [Method="POST"] to [Method="GET"]. And then change the script in tinput.php too, from $_POST to be $_GET. Now refresh your browser and click the submit button, the result will look like Picture 3 below.
Picture 3. forminput2.php

And that's all, thanks for coming ...




Share your views...

1 Respones to "PHP for Beginners, Fast and Simple Learning"

h said...

Next PHP OOP for Beginners

Post a Comment

NO SPAM PLEASE!

 

©2013 @namakuherman | Developed by Herman Creative Industry