2

Is there something wrong in this simple code? I'm trying to store input type weight into a php variable $w....tried echo $w to check if it has been stored but it doesn't display anything..:p

<html>
<head>
<title></title>
</head>
<body>
<form action='' method='POST'>
    <label>Enter Weight: </label><input type='text' name="weight">
</form>
<?php 
   $w=$_POST["weight"]; 
   echo $w; 
?>

1 Answers1

0

It should work as expected

What you have to do is to assign after checking is done

if (isset($_POST['weight']))
{ 
   $w=$_POST["weight"]; 
   echo $w; 
}

So your code should be

<html>
<head>
<title></title>
</head>
<body>
<form action='' method='POST'>
<label>Enter Weight: </label><input type='text' name="weight">
<input type="submit">
</form>
<?php 
if (isset($_POST['weight']))
{

   $w=$_POST["weight"]; 
   echo $w; 
}
?>

And it should display your input after the submit button is pressed.

Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63