0

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);
?>
3
  • You're specifying that you're providing 2 columns, but actually provide 3? INSERT INTO courses (studentid, ckb) VALUES ('$studentid', '$cc', $fname) Commented Jun 25, 2014 at 0:41
  • Had you error reporting "on", it would have signaled a mismatch set of values/columns. Commented Jun 25, 2014 at 0:42
  • Thanks ! that's it for sure , however I'm getting file not found after uploading the fixed connect-mysql.php file... Commented Jun 25, 2014 at 0:51

1 Answer 1

3
 $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.

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

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.