pepe
pepe

Reputation: 9909

Radio buttons checked however passing NULL to database

I have 4 groups of radio buttons that are presented unchecked to the user. The user then needs to check one radio button for each group. When I submit this form, the error I get is that, for example, for picture_6.tif the value being passed is NULL.

I am using CodeIgniter and the form is being submitted via POST. I wonder if you could tell me what I'm doing wrong.

<form action="/log" method="post" accept-charset="utf-8">
    <table class="static">
        <tbody>
            <tr>
                <td><input type="radio" name="picture_6.tif" value="0" class=""></td>
                <td><input type="radio" name="picture_7.tif" value="0" class=""></td>
                <td><input type="radio" name="picture_8.tif" value="0" class=""></td>
                <td><input type="radio" name="picture_9.tif" value="0" class=""></td>
            </tr>
            <tr>
                <td><input type="radio" name="picture_6.tif" value="1" class=""></td>
                <td><input type="radio" name="picture_7.tif" value="1" class=""></td>
                <td><input type="radio" name="picture_8.tif" value="1" class=""></td>
                <td><input type="radio" name="picture_9.tif" value="1" class=""></td>
            </tr>
            <tr>
                <td><input type="radio" name="picture_6.tif" value="2" class=""></td>
                <td><input type="radio" name="picture_7.tif" value="2" class=""></td>
                <td><input type="radio" name="picture_8.tif" value="2" class=""></td>
                <td><input type="radio" name="picture_9.tif" value="2" class=""></td>
            </tr>
            <tr>
                <td><input type="radio" name="picture_6.tif" value="3" class=""></td>
                <td><input type="radio" name="picture_7.tif" value="3" class=""></td>
                <td><input type="radio" name="picture_8.tif" value="3" class=""></td>
                <td><input type="radio" name="picture_9.tif" value="3" class=""></td>
            </tr>
            <tr>
                <td><input type="radio" name="picture_6.tif" value="9" class=""></td>
                <td><input type="radio" name="picture_7.tif" value="9" class=""></td>
                <td><input type="radio" name="picture_8.tif" value="9" class=""></td>
                <td><input type="radio" name="picture_9.tif" value="9" class=""></td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <td>
                    <div>
                        <input type="submit" name="mysubmit" value="Submit Post!">
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</form>

EDIT: Just adding this to make it easier for searching. The error arises from using periods in a name attribute.

Upvotes: 0

Views: 949

Answers (1)

Alex Kudryashev
Alex Kudryashev

Reputation: 9460

You named your radio name="picture_6.tif" and in php your parameters available as $_POST["picture_6_tif"]. Note: not $_POST["picture_6.tif"]. The latter is null as undefined.

<?php
var_dump($_POST);
?>
//array(5) { ["picture_7_tif"]=> string(1) "1" ["picture_6_tif"]=> string(1) "2" ["picture_8_tif"]=> string(1) "3" ["picture_9_tif"]=> string(1) "9" ["mysubmit"]=> string(12) "Submit Post!" } 

Upvotes: 3

Related Questions