Search code examples
phpformspostmethodsget

About Form method's


As a junior trying to make form like google form and I want to collect data using GET/POST form methods in my project. I tried some code in books but I get clear page or no output from the form. Also, I want only to see this data not to appear to clients, what is the best way to do that?

Simple code I used:

/* PHP --- index.php*/


<form action="collect.php" method="POST"> 
    <input type="text" name="name" id="inputName">
    <br><br>
    <input type="password" name="name" id="inputNumber">
    <br><br>
    <input type="submit" value="Login">
</form>

Used this codes

/*collect.php*/


<?php

$id = '';
$name ='';

if(isset($_GET['id']))
  $id = $_GET['id'];

if(isset($_GET['name']))
  $name =$_GET['name']; "<br>";

    echo $id . '-' . $name;

foreach($_GET as $key=>$value){
    
    echo $key . '=' .$value . '<br>';
}

?>

<?php

foreach($_POST as $key=>$value){
    
    echo $key . ': ' . $value . '<br>';
    
}
?>

Solution

  • Try to change your form action to this action="./collect.php"