View Full Version : Expire's [TUTS] N0.2. How to start work with web developing language [PHP] and [MySQL] Database

08-22-2014, 09:32 PM
In my first "tut" you saw how to make variables and output them in simplest ways.
Now we gonna talk about why the ***** we need them and what we can make with them and HTML form.
All tutorial will be inside CODE.


Okay guys now just look at the code and follow the comments it will be easier for you and me of course :)
how you already see we will be talking about saving info to variables and do "things" with them.

// Create the variable named $url to grab all data from website address bar and check our stage in form with super global $_GET
$url = isset($_GET['stage']) ? $_GET['stage'] : null;

if(isset($_GET['stage'])) { // check if the our stage set in this case it will be 2

echo "We are at stage 2 <br />"; // output simple text that tells us that we are at stage 2
echo "<a href = 'tutorial.php'>Go back to stage One</a>"; // making link to go back to stage 1

if(isset($_POST['submit'])) { // check if the button submit was pressed

//echo "Your name is : " .$_POST['name']; // output the info from input name with super global $_POST
//echo "Your age : ". $_POST['age']; // do the same for the age
You can output your form info like that but think if we need to save our value and use it many times or just do simple
calculating it becomes more complicated, that why we use variable to save our info there is two ways to do that I will show now both of them.

/* The first one will be
$name = $_POST['name'];
$age = $_POST['age'];
Output them will look like that
echo "Your name is : $name and you $age years old !";

/* The second way
Making array for that

$inputValues = Array('name' => ''.$_POST['name'].'', age = $_POST['age'],);
Now to output them we have to call our array values.
echo "Your name is : {$inputValues[name]} and you : {$inputValues['age'] Years old !}";


// In both ways we will have the same output, I prefer use array with much more inputs for example like 10 15 and more, it's more comfortable FOR ME.
// Choose your way to do that.

Now what we can do with our variables? answer is simple ANYTHING !
Make simple calculation for age.
$ageMultiplier = 4 Creating new variable with integer value 4
I'll show how to do that in both ways for your saved variables.

echo "Your name is : $name and you $age years old ! After $ageMultiplier years you will be : " . $age + $ageMultiplier . " Years old ";
echo "Your name is : {$inputValues['name']} and you {$inputValues['age']} years old ! After $ageMultiplier years you will be : " . $inputValues['age'] + $ageMultiplier . " Years old ";
In both ways we get the same output, again it depends on which one you feel more comfortable.



} else {


<form action = 'tutorial.php?stage=2' method = 'POST'>
<input type = 'text' name = 'name' placeholder = 'Enter your name here' />
<input type = 'text' name = 'age' placeholder = 'Enter your age here' />
<input type = 'submit' name = 'submit' value = 'submit'/>

<?php } ?>

This is the simplest way to manipulate with HTML forms.
In next tutorial i'll show you how to make simple register and login system with sessions. :)
Hope you enjoy!