Hi

I am trying to insert to database. I am facing an issue in getting relavent radio button value. suppose if i select 1 or 2 or 3 radio button, by default it display 1 radio button value. please help me to fix the issue.

index.php

<div id="message"></div>
                        <form class="form-horizontal" id="registerform" action="conreg.php" method="post" name="registerform">
                            <div class="title">
                                <h3>Create An Account</h3>
                            </div><!-- end title -->

                            <div class="form-group">

                                <div class="col-sm-10">
                                    <input type="text" id="firstname" name="firstname" class="form-control" placeholder="First name" required>
                                </div>
                            </div>
                            <div class="form-group">

                                <div class="col-sm-10">
                                    <input type="text" name="lastname" id="lastname" class="form-control" placeholder="Last name" required>
                                </div>
                            </div>
                            <div class="form-group">

                                <div class="col-sm-10">
                                    <input type="email" name="email" id="email" class="form-control" placeholder="Email" required>
                                </div>
                            </div>
                            <div class="form-group">

                                <div class="col-sm-10">
                                    <input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
                                </div>
                            </div>
                            <div class="form-group">

                                <div class="col-sm-10">
                                    <input type="password" name="confirm_password" class="form-control" id="confirm_password" placeholder="Re-enter password" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-10">
                                    <label>Current versione</label>
                                    <select id="lstjde" name="lstjde[]" multiple="multiple" required>
                                        <option value="A1 8.0">A1 8.0</option>
                                        <option value="8.9">8.9</option>
                                        <option value="8.10">8.10</option>
                                        <option value="8.11">8.11</option>
                                        <option value="8.12">8.12</option>
                                        <option value="9.1">9.1</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">

                                <div class="col-sm-12">
                                    <label>When do you plan to upgrade</label>                        
                                    <label class="radio-inline"><input type="radio" id="upgrade" value="Next 6 Months" name="upgrade" required>Next 6 months</label>
                                    <label class="radio-inline"><input type="radio" id="upgrade" value="Some Time Next Year" name="upgrade" required>Some Time Next Year</label>
                                    <label class="radio-inline"><input type="radio" id="upgrade" value="Yet to Plan" name="upgrade" required>Yet to Plan</label>
                                </div>
                            </div>
                                <input type="hidden" class="form-control" name="regdate" id="regdate" value="<?php echo date('Y/m/d H:i'); ?>">
                            <div class="form-group">
                                <input type="submit" id="submit" class="btn btn-primary" value="Register">
                            </div>
                        </form>
                        <script src="../js/jquery.user-register.js"></script> 

conreg.php

$firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $confirm_password = $_POST['confirm_password'];
    $regdate = $_POST['regdate'];
    $lstjde = $_POST['lstjde'];
    $upgrade = $_POST['upgrade'];

    $contactName = $firstname.' '.$lastname;
    $lstjde_list = implode(",",$lstjde);

jquery.user-register.js

jQuery(document).ready(function(){

    $('#registerform').submit(function(){

        var action = $(this).attr('action');

        $("#message").slideUp(750,function() {
        $('#message').hide();

        $('#submit')

            .attr('disabled','disabled');

        $.post(action, {
            firstname: $('#firstname').val(),
            lastname: $('#lastname').val(),
            email: $('#email').val(),
            password: $('#password').val(),
            confirm_password: $('#confirm_password').val(),
            regdate: $("#regdate").val(),
            lstjde: $("#lstjde").val(),
            upgrade: $("#upgrade").val(),

            verify: $('#verify').val()
        },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown('slow');
                $('#registerform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled');
                if(data.match('success') != null) $('#registerform').slideUp('slow');

            }
        );

        });

        return false;

    });

});

there can be only rone adio selected in a group

you group them assigning the same name attribute
in POST you will receives the value of the selected radio

TexWiller is correct, this code seems to be accurate since you only want one value from the radio button, or you would be using a checkbox. You can only select one radio button within a form, so the value is unset when you POST the data.

If you give them different names, you can identify which was seleteted.

if(isset($_POST['upgrade1']))
{
    $upgrade = $_POST['upgrade1'];
}
elseif(isset($_POST['upgrade2']))
{
    $upgrade = $_POST['upgrade2'];
}

if(isset($_POST['upgrade3']))
{
    $upgrade = $_POST['upgrade3'];
}

Also, a general note, it's good practice to also validate your form data server side in addition to client side with JavaScript. It can be very easy to POST data direct to the server, which will then bypass any sort of validation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.