Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP post on same page

Tags:

html

php

I have this code, and I want to send a message when the password = hello. But the page shows immediadly the text: 'good pass' and 'bad pass'

What's wrong with this code?

<body>
<?php
if(isset($_POST['submit'])) 
{
    $wachtwoord = ($_POST['wachtwoord']);

    if ($wachtwoord = "hello")
    {
     ?><h1>Good pass</h1><?php;
    }

    else 

    if($wachtwoord != "hello")
    {
    ?><h1>Wrong pass.</h1><?php;
    }
} 

else 
{
?>
<center>
    <br><br><br><br>
        <table>
            <tr><td>Hello User, <br><br><hr>
            <b><a href="link0/">DirectAdmin</a><br><br>
            <a href="link1/">PHPMyAdmin</a></b><br>
            <form action="" method="POST">
            <input name="wachtwoord" type="text" /><input type="submit" name="submit" value="Go" /></td></tr>
            </form>
        </table>
    <br><br>
    </center>
<?php
}
?>
</body>
like image 842
Thijs Kempers Avatar asked Sep 14 '26 00:09

Thijs Kempers


2 Answers

You're presently assigning if ($wachtwoord = "hello") with a single equal sign =

Use two like this: == then do if ($wachtwoord == "hello") in order to compare.


  • Assignment operator => =

  • Comparison operator => ==

like image 180
Funk Forty Niner Avatar answered Sep 15 '26 13:09

Funk Forty Niner


You are assigning the value hello to the variable $wachtwoord in this code

if ($wachtwoord = "hello")
                ^
    {
     ?><h1>Good pass</h1><?php;
    }

You have to use comparison operator(==) instead of using assignment operator (=). Change it to

if ($wachtwoord == "hello")
                 ^ 
    {
     ?><h1>Good pass</h1><?php;
    }
like image 33
Jenz Avatar answered Sep 15 '26 15:09

Jenz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!