-1

I tries validating the form values by using the echo function but it did not work it didn't display on the top like how i expected can you help me. this is the php code :

<?php
if(isset($_POST['Submit']))
{
    $username=isset($_POST["username"]);
    $password=isset($_POST["password"]);
    echo "your name is".$username."and your password is ".$password;
}
?>

the form html code is :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="form.php" methode="post">
        <input type="text" name="username" placeholder="enter your name">
        <input type="password" name="password" placeholder="enter your password"/><br>
        <input type="Submit" name="Submit"/>
    </form>
</body>
</html>
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
Epicc7zek
  • 1
  • 3
  • 1
    Get rid of `isset()`. You're using it wrong. – John Conde Nov 16 '15 at 21:14
  • nitpick: `echo` is not a function. it's a language construct. and `isset()` returns a boolean true/false, which you then try to echo out. It does **NOT** return whatever value you're testing in the variable. – Marc B Nov 16 '15 at 21:17
  • but without the isset() funtion I can not know if the submit button has been checked ! it should be true to execut the construction – Epicc7zek Nov 16 '15 at 21:24
  • get rid of `isset` on your `$username` and `$password` – Andrew Nov 16 '15 at 21:30

2 Answers2

0

Using isset checks that there is a value for the thing you specify. In this case the 'username' index in the $_POST superglobal. So writing $username = isset($_POST["username"]) is returning a boolean, not the string value you are trying for. If you want the string value of $_POST['username'], use a ternary around the isset like this:

$username = (isset($_POST['username']) ? $_POST['username'] : 'Some flavor of not set error';
Vikingord
  • 53
  • 7
0

In the form, the method attribute is mistakenly spelled with an "e" at the end. Once you change it to "method" your post should start working.

Jacob Valenta
  • 6,659
  • 8
  • 31
  • 42
quinnk31
  • 1
  • 1