简体   繁体   中英

Storing Data to MySQL database from html form with checkboxes

I have an html form with checkboxes and I managed to store the values using an array to my database .

I added a name field to the form, and added a column on mysql table .

The problem is, the newly added name field is not storing any values and is malfunctioning the previous code. I'm pretty sure my definition for the $fname value is incorrect, here is the full php code

$dbcon = mysqli_connect("$host","$username","$password","$db_name") ;           

        if (!$dbcon) {
        die('error connecting to database'); }

        echo 'Courses successfully registerd , ' ;  

    // escape variables for security
    $studentid = mysqli_real_escape_string($dbcon, $_GET['studentid']);
    $fname = $_POST["name"]; 

// Get Cources
$name = $_GET['ckb'];
if(isset($_GET['ckb']))
{
foreach ($name as $courcess){
$cc=$cc. $courcess.',';
}
}

    //$ckb = join (', ', var_dump($_POST['ckb'])); 


    $sql="INSERT INTO courses (studentid, ckb)
    VALUES ('$studentid', '$cc', $fname)";

    if (!mysqli_query($dbcon,$sql)) {
    die('Error: ' . mysqli_error($dbcon));
}
echo "  Thank you for using IME Virtual Registeration  ";   
        mysqli_close($dbcon);
?>
 $sql="INSERT INTO courses (studentid, ckb)
VALUES ('$studentid', '$cc', $fname)";

is your problem. You are attempting to insert three values into two fields. You need to add your new field after ckb so that the argument $fname can be inserted into it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM