vendredi 28 août 2015

How to store data into multiple MySQL tables according to the checkbox value?

I have an html form, with multiple checkboxes (subjects) When a user (student) selects the subjects ,the StudentID is stored in a MySQL table along with the selections made in separate columns but in the same table.

My question is: How can I store the student ID in a new table if the checkbox value "equals" to something, would strpos do it ?

for example:

if (strpos($cc,'252000') !== false) {
    mysqli_query($dbcon,"INSERT INTO newtable (studentid,ckb) 
VALUES ('$studentid','$cc')");
}

Full Code:

<?php
      $host = 'localhost';
      $port = 8889;
      $username="root" ;
      $password="root" ;
      $db_name="db1" ;
      $tbl_name="courses" ;
      $tbl_name="studentinfo";
      $tbl_name="newtable";

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


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


    $studentid = mysqli_real_escape_string($dbcon, $_GET['studentid']); //echo $studentid;

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

if (strpos($cc,'252000') !== false) {

    mysqli_query($dbcon,"INSERT INTO newtable (studentid,ckb) 
VALUES ('$studentid','$cc')");

    echo "$cc, trtue";
}

HTML

<form action="cdb.php" method="get">

<input name="studentid" type="text" id="studentid" maxlength="11"value="Student ID" />

<input type="checkbox" name="ckb[]" value="251000-1"/>
<input type="checkbox" name="ckb[]" value="251000-2"/>




Aucun commentaire:

Enregistrer un commentaire