0

So in my website is table which contains data from database. After button is clicked It truncate database table. I need to make that button will be click-able after password is entered. But I can't to It successfully.

Here are 2 fields "Username" and "Password". After button is clicked I don't get any errors It always truncate database. For this is needed to use (delete_table.php)

PHP

$username = $_POST['user'];
$password = $_POST['password'];
if ($username=="name1" || $username=="name2") {
    if ($password=="thepassword") {
        include("delete_table.php");
    } else {
        echo "Username or Password not entered correctly please try again.";
    }
} 

HTML

<form method="post" action="delete_table.php" style="border:#000000 2px solid; width:375px;">
Username: 
<input type="text" name="user" size="35" />
<br />
Password:
<input type="password" name="password" size="35" /><br />
<input type="submit" id='delete' class='delete' name="delete" value='Išvalyti sąrašą'></input>
</center>
</form>

1 Answer 1

0

you need Javascript for this because this is an clientside action:

<input type="password" name="password" size="35" id="password" /><br />
<input type="submit" id='delete' class='delete' disabled name="delete" value='Išvalyti sąrašą' />


document.getElementById('password').onkeyup = function(){
    document.getElementById('delete').disabled = false;
}

And a jsFiddle Demo


I've added an id to the password so we can easily bind an event to it, the javascript code does that. I also added 'disabled' to the button, and in the eventfunction, I set that to false (so not-disabled->enabled).

Also, its not <input></input>, but <input />. Might be because you started with <button>, but worth a mentioning :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.