1

I'm experimenting with forms and I can't tell why the cod below wont echo out the supposed result. Why am doing wrong and how do I get it to echo out user input.

<?php

//way to tell if the form has been submitted (If form not submitted, display form again.)
if (!isset($_POST['submit'])){

?>

    <form method="post" action="" />
    <input type="text" name="city" />
    <input type="submit">

</form>

<?php
//Process input
}
else
{

// Retrieve information from form submission.

$username = $_POST['city'];
echo "Your name is $username.";
}
?>
Sleek Geek
  • 4,638
  • 3
  • 27
  • 42

1 Answers1

0

give your submit button a name property:

//way to tell if the form has been submitted (If form not submitted, display form again.)
if (!isset($_POST['submit'])){

?>

    <form method="post" action="" />
    <input type="text" name="city" />
    <input type="submit" name="submit">

</form>

<?php
//Process input
}
else
{

// Retrieve information from form submission.

$username = $_POST['city'];
echo "Your name is $username.";
}
?>
David Zorychta
  • 13,039
  • 6
  • 45
  • 81