jeudi 13 juillet 2017

How to remember checkbox preference in user account in html/php site

Good day!

I'm doing a site. There is a checkbox which update the option I choose in phpmyadmin.

But if I press f5/reload page, the preference I choose disappears on client/html side, (look the image for better understanding)

Image, open me!

So basically I want the site remember my choice in the "user account" I tried with

  <form action="pr.php" method="POST">
  <h3 style="color:red;">Numbers?</h3>
  <input type="checkbox" name="a1" value="1" <?php if(isset($_POST['a1'])) echo "checked='checked'"; ?>  /><label>One</label><br/>
  <input type="checkbox" name="a2" value="2" <?php if(isset($_POST['a2'])) echo "checked='checked'"; ?>  /><label>Two</label><br/>
  <input type="checkbox" name="a3" value="3" <?php if(isset($_POST['a3'])) echo "checked='checked'"; ?> /><label>3</label><br/>
  <input type="checkbox" name="a4" value="4" <?php if(!is_null($_POST['a4'])) echo "checked='checked'"; ?> /><label>Four</label><br/>

  <input type="submit" value="submit" name="submit">

It doesnt work with isset, empty or is_null.

Thanks for all!

Aucun commentaire:

Enregistrer un commentaire