samedi 19 décembre 2020

Save checkbox value to user's account

I started a website, I created a login and a register form with a database. The users can log in. I wan to make a form with checkboxes, the users need to check the box when they completed a level. I write the main html and the php, but when i click on submit i recive a 500 error.

main htlm:

<?php
session_start();
if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {
      // redirect to your login page
      exit();
}

$username = $_SESSION['username'];
// serve the page normally.
?>




<!DOCTYPE html>
<html>
<body>
<h1>Szia, <b><?php echo htmlspecialchars($_SESSION["username"]); ?>
<form method="post" action="kcheck.php">
<input type="checkbox" name="levels[]" value="a">3b
<br>
<input type="checkbox" name="levels[]" value="b">5c
<br>
<input type="checkbox" name="levels[]" value="c">9a
<br><br>
<input type="submit" value="submit">
</form> 

</body>
</html>

An the "kckeck.php"

    <?php
session_start();
$_SESSION['username']  = 4;
$username =$_SESSION['username']


$username = $_SESSION['username'];
// serve the page normally.

$conn = mysqli_connect('sql102.epizy.com','epiz_27471802','epiz_27471802_users','****')


$sql = "INSERT INTO users(levels)VALUES( '$chk' )";

if(mysqli_query($conn,$sql)) {

    echo 'Data added sucessfully';
} 
else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>

I hope that You can help me :)




Aucun commentaire:

Enregistrer un commentaire