Accessing form variable in php 

Accessing form variable in php 

Accessing form variables are important topic in php web pages applications.this php is helps to validate that data given by the user.this php application consists of checkbox,radio buttons,text fields etc..,

These all are accessing form of a input data given by the user with interacting with application fields.

In php we can access form by using only two commands.one is $_POST and another is $_GET.these two variables are used for taking inputs from user in the form and validate that data.

$_GET is used to search that content in the url.it displays on url of the browser.it is less secure because some of the content is visible on the browser.

In Get we can send only limited information.we cannot send any large data.

$_POST is used the get the content from the form.it is not visible on url like values, variable names.it is more secure than get.we can send unlimited data to the user.

<form method=”post” action =”hello.php”>

method:

In php method attribute is used to check it send data from $_post method or $_get method.

Action:action is the attribute in php .it is used to for where the data is submitted and from where data is sending.

Name:

Name field is important in php .it is used to submit data in form.

$user=$_POST[‘user’];

Target:

Target attribute is crucial in php.it is used to display the data after submitting the form.

<form method=”post” action =”hello.php”>

<Input type=”text” name=”user”>

<input type =”submit” value=”submit”>

</Form>

Example:

<form method=”get” action=”hello.php”>

Age:<input type=”text” name=”age”>

<input type=”text” value=”submit”>

</form>

hello.php

<?php

$age=$get[‘age’];

echo “age : “.$age;

?>

Output:

age : 25

Variable handling functions in php:

Variable handling functions are predefined functions.we cannot install any function in php.there are function in php we can access it easily.

1.isset()

2.empty()

3.unset()

4.gettype()

5.settype()

6.is_int()

7.is_float()

8.is_string()

9.is_bool()

10.is_null()

11.is_array()

12.is_object()

13.is_numeric()

14.intval()

15.floatval()

16 strval()

17.var_dump()

18.print_r()

1.isset():

It is used to check wheather variable is assigned or not.

If it is assigned it prints true.otherwise it prints false.

Example:

<?php

$name=”hi”;

if(isset($name))

{

echo “true”;

}

?>

Output:

true

2.empty():

empty() function is used to check variable is empty or not.empty means null..,nothing value is assigned.

<?php

$name=” “;

if(empty($name))

{

echo “true”;

}

?>

Output :

true

3.gettype()

Gettype() is used to check which datatype is used to store the values .

It return the data type of that variable.

Example:

<?php

$name=”hi”;

echo gettype($name);

?>

Output:

string

4.is_int()

It is used to check whether given variable is integer or not.

<?php

$a=10;

if(is_int($a))

{

echo “true”;

}

?>

Output:

true

5.is_float()

it is used to check whether given variable is float or not

<?php

$a=12.5;

if(is_float($a))

{

echo “yes”;

}

?>

Output :

yes

6.is_string()

Is_string() is used to check whether given variable is string or not.

<?php

$a=”hello”;

if(is_string($a))

{

echo “yes”;

}

?>

Output:

Yes

7.var_dump()

var_dump() is one the important function in php.it is used to give variable value.

It also displays the data type of that variable.

<?php

$a=100;

var_dump($a);

?>

Output:

Int(100)

8.unset()

Unset is used to delete the variable value.

Isset is used to check the value is assigned or not.

<?php

$a=100;

unset($a);

echo isset($a);

?>

Output:

No output

9.is_bool()

It is used to check whether given variable Boolean or not.

<?php

$b=”true”;

if(is_bool($b))

{

echo”true”;

}

?>

Output :

true

10.print_r()

It is used to print array element one after another easily.

<?php

$c=(“cat”,”dog”);

print_r($c);

?>

Output:

[0]cat

[1]dog

Leave a Comment