Post and get ! In php | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Post and get ! In php

who can give me some example

8th Apr 2017, 7:14 PM
louay abidi
louay abidi - avatar
2 Answers
+ 17
<?php echo isset($_GET["a"])?$_GET["a"]:""; ?> <form action="" method="get"> <input type=text name=a> </form>
8th Apr 2017, 9:13 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
IMHO, by default a form HTML tag is using HTTP GET method, and if you don't specifying action attribute value than the form'll be submitted to that page it self. In PHP you can catch this submitted value by $_GET global variable eg: <form> Input your fullname <input type="text" value="fullname"> <input type="submit"> </form> <?php if(isset($_GET['fullname'])){ echo "you're inputing : ".$_GET['fullname']; } ?> if you want to submitted the form with HTTP POST method, you must specifying method attribute to POST. In PHP you can get this submitted value using $_POST global variable eg: <form method='POST'> Input your fullname <input type="text" value="fullname"> <input type="submit"> </form> <?php if(isset($_POST['fullname'])){ echo "you're inputing : ".$_POST['fullname']; } ?> When you want to send the value to another page, you need put the value for action attribute on form tag, eg: <form method='POST' action="anotherpage.php"> Input your fullname <input type="text" value="fullname"> <input type="submit"> </form> and the value can you get on 'anotherpage.php' with code below: <?php if(isset($_POST['fullname'])){ echo "you're inputing : ".$_POST['fullname']; } ?> cmiiw :)
8th Apr 2017, 11:43 PM
cahya dwiana sn
cahya dwiana sn - avatar