-1

So when a user creates an account and they have to tick the checkbox to proceed which works, but how do I store that they accepted it (even though they cannot make an account without accpecting it). But we want to store it nonetheless.

Checkbox

<input type="checkbox" name="agree" value="accepted">

PHP

if ($_POST['agree'] != 'accepted') {
             $error[] = 'Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy';
    } else {
            $stmt = $db->prepare('SELECT termsAccepted FROM members WHERE termsAccepted = :??????');
    $stmt->execute(array(':??????' => $?????));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);

    }
1

2 Answers 2

0

If the checkbox isn't checked, there wont be any agree index in the $_POST variable so check its existence beforehand to prevent throwing warnings in the log.

After that you can use an UPDATE query to modify the column termsAccepted in your members table.

pseudo code:

if (isset($_POST['agree']) && $_POST['agree'] == 'accepted') {
    $stmt = $db->prepare('UPDATE members SET termsAccepted=1 WHERE id = :user_id');
    $stmt->execute(array(':user_id' => $user_id));
}

Tip: If you're only storing true or false, you can use the datatype TINYINT(1) or BOOLEAN for the column termsAccepted as it stores only two states.

Sign up to request clarification or add additional context in comments.

Comments

0

You can make a if query in your "else" query

if ($_POST['agree'] == 'accepted') {
 $checkbox = "true";
} else {
 $checkbox = "false";
}

And than you can add $checkbox to your executing array, but you should revise the prepared statement.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.