0

Now i made a simple form with 2 input one for name and one for button i want in php file echo name input

<form action="del.php">                                     
<input type="text"  name="name" />
<input type="submit" name="btn" value="button"/>
</form>

in del.php

<?php
session_start();
$_SESSION['name'] = $_POST['name'];
echo "".$_POST['name'].""; 

giving me white screen when every time i want to echo any thing that typed in this input

reko beko
  • 86
  • 1
  • 1
  • 10

3 Answers3

4

You are missing method attribute in your form.

<form action="del.php" method="POST">                                     
    <input type="text"  name="name" />
    <input type="submit" name="btn" value="button"/>
</form>

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post").

Source: https://www.w3schools.com/tags/att_form_method.asp

Community
  • 1
  • 1
Anis Alibegić
  • 2,941
  • 3
  • 13
  • 28
1

the default method when a form is submitted is GET, you need to specify the POST method (method="post") in your <form> tag:

<form action="del.php" method="post"> 
Wee Zel
  • 1,294
  • 9
  • 11
0

Your form is not POSTing its GETing (see the url params which will be set example.com?name=) this is because you not set the from method for POST:

<form action="del.php" method="post">                                     
    <input type="text"  name="name" />
    <input type="submit" name="btn" value="button"/>
</form>

And within your PHP you should check its post and check that the values are set:

<?php 
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $name = isset($_POST['name']) ? $_POST['name'] : null;

    // set your session - not sure you need this :/
    $_SESSION['name'] = $name;

    // echo out your result but also protect from XSS by using htmlentities
    echo htmlentities($name); 
}
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106