0

I am a newible on php and I am following a video to learn inserting data in website to database, but I face a huge problem.

As I am going to from many groups from many members, i create some checkboxs for member to register. I followed this video tutorial,but have error.

<?php
//$_SESSION['name'];
session_start();
echo "student";
?>

<form action="" method="POST">    
<input type="checkbox" name="group[]" value="group1">group1<br>
<input type="checkbox" name="group[]" value="group2">group2<br>
<input type="checkbox" name="group[]" value="group3">group3<br>
<input type="checkbox" name="group[]" value="group4">group4<br>
<input type="checkbox" name="group[]" value="group5">group5<br>

<input type="submit" name="submit" value="submit">   
</form>

<?php

    if  (isset($_POST['submit']))
    {
        //print_r($_POST);
    echo implode(',', $POST['group']);
}
?>

</h1>
<a href="logout.php">Logout</a>

All things that I wanna do was followed for these coding but still have error

Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\fyp\student.php on line 37

echo implode(',', $POST['group']);

what was wrong with it, thank you for any suggestion

2 Answers 2

1

You are missing $_ before POST .

Instead of this

echo implode(',', $POST['group']);

use this

echo implode(',', $_POST['group']);
Sign up to request clarification or add additional context in comments.

Comments

0

You're forgetting the underscore before the POST. Here is that line fixed:

echo implode(',', $_POST['group']);

There are a few other simple issues that might cause some trouble later on. First, in terms of syntax, you should close your HTML input tags (like below):

<input type="checkbox" name="group[]" value="group1" />group1<br>
...

Next, you will get this same error when no checkboxes are selected as the variable $_POST['group'] has not been defined yet. You can use the PHP empty() function to test this variable (http://php.net/manual/en/function.empty.php) before you call the implode().

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.