mercredi 5 avril 2017

Php checkbox to update enum in mysql and preload status

To activate or deactivate a user's account I am trying to create a toggleswitch (actually a checkbox) on a form that administrators can flip. I have an enum column in mysql user's db table that is either '1' (account active) or '0' (user can't log in), and if I set it manually in mysql, it works.

Using some old questions on Stack I have created the checkbox/toggleswitch, but I have two problems - I can't get it to insert/change the value in the db, although when I echo the result it seems to be ok. Second problem is that this is for a form for editing user information, so it preloads the user's name etc, but I need the 'switch'/checkbox to be in the correct position for the admin when they open the form (either 'checked' or 'unchecked').

This is my code

<tr>
            <td align="right">Account Active:</td>
            <td>
            <input type="hidden" name="activate" value='1'/>
            <input type="checkbox" class="toggle-switch" align="center" name="activate" value='0'>
            </td>
            </tr>


        <tr align="center">
            <td colspan="8"><input type="submit" name="update_user" value="Update User Details"/></td>




Aucun commentaire:

Enregistrer un commentaire