How to get the value of the textbox?

Asked

Viewed 694 times

0

I want to get the value I’m gonna write on my textbox. All on the same page to then change a table field by the value inserted in textbox.

<form method="POST" action="#">

    <input type=text required name='txtnewpass' autofocus style='width:150px' value='<?php echo "$txtnewpass"; ?>'>
    <input type=submit name=Alterar value=Alterar>

</form>

PHP

if ($_POST['txtnewpass']){
 $txtnewpass = $_POST['txtnewpass'];
}

$base_hndl  =   new SQLite3($dir.$base);
$requete = "UPDATE 'users' SET 
            password='$txtnewpass'
            WHERE login='$login'";
$resultat = $base_hndl->exec($requete); 
echo "<br><b><center>password change</center></b>";
  • What is the Undefined index problem? it would be nice to put an isset() in if.

  • Yes that’s the mistake.

  • 1

    probably the stick you’re giving is a generic PHP warning, which you can resolve by changing the configs of php.ini, reads this: http://stackoverflow.com/questions/15949304/turn-off-display-error-php-ini

  • I changed the if to if (isset($_POST['txtnewpass']))

  • The code works, but it always gives me the Undefined error

1 answer

1

Put all the code inside if. If you don’t receive values you don’t want me to update the database.

if ($_POST['txtnewpass']){
    $txtnewpass = $_POST['txtnewpass'];

    $base_hndl  =   new SQLite3($dir.$base);
    $requete = "UPDATE 'users' SET 
                password='$txtnewpass'
                WHERE login='$login'";
    $resultat = $base_hndl->exec($requete); 
    echo "<br><b><center>password change</center></b>";
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.