Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:22:19+00:00 2026-06-14T13:22:19+00:00

I’m new in web programming and I really need your help. I have a

  • 0

I’m new in web programming and I really need your help. I have a form with several radio buttons and I want to insert them into mysql through an ajax post. I can do it for a single button but for more than one I don’t have idea how to do it.

This is a part of my html and jquery:

<html>
    <script>
        $(document).ready(function () {
            $("#submit").click(function () {
                var q1 = $('input[type="radio"]:checked').val();
                if ($('input[type="radio"]:checked').length == "0") {
                    alert("Select any value");
                } else {
                    $.ajax({
                        type: "POST",
                        url: "ajax-check.php",
                        data: "q1=" + q1,
                        success: function () {
                            $("#msg").addClass('bg');
                            $("#msg").html("value Entered");
                        }
                    });
                }
                return false;
            });
        });
    </script>
    </head>
    <body>
        <div id="msg"></div>
        <form method="post" action="">
            <div class="Clear">
                question1:bla bla bla
                <input class="star required" type="radio" name="q1" value="1" />
                <input class="star" type="radio" name="q1" value="2" />
                <input class="star" type="radio" name="q1" value="3" />
                <input class="star" type="radio" name="q1" value="4" />
                <input class="star" type="radio" name="q1" value="5" />
            </div>
            <br />
            <div class="Clear">
                question2:bla bla bla
                <input class="star required" type="radio" name="q2" value="1" />
                <input class="star" type="radio" name="q2" value="2" />
                <input class="star" type="radio" name="q2" value="3" />
                <input class="star" type="radio" name="q2" value="4" />
                <input class="star" type="radio" name="q2" value="5" />
            </div>
            <input type="submit" name="submit" id="submit" />
        </form>
    </body>
</html>

And here is how I insert the button in mysql:

<?php
$query = mysql_connect("localhost", "root", "");
mysql_select_db('db', $query);

if (isset($_POST['q1'])) {
    $choice1 = $_POST['q1'];
    $choice2 = $_POST['q2'];
    mysql_query("INSERT INTO tb VALUES('','$choice1')");
}
?>

I’ve tried to make a var for each button but dosen’t worked.
How could I post all values in php and what should I change into my ajax and php?
Thanks!

This is how I did the .php

<?php
$query=mysql_connect("localhost","root","");
mysql_select_db('cosmote',$query);
$q = array();
for ($i = 1; $i <= 2; $i++) {
  $q[$i] = isset($_POST['q'+$i]) ? mysql_real_escape_string($_POST['q'+$i]) : 0;
}
mysql_query("INSERT INTO tabel (q1,q2) VALUES ('$q[1]','$q[2]')");
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:22:20+00:00Added an answer on June 14, 2026 at 1:22 pm

    OK, here is how to do it. First, add an id to the form:

    <form id="myform" method="post" action="">
    

    This will make it easier to access via jQuery. Then, pass the serialized form as the POST data to your PHP script:

    $(document).ready(function () {
        $("#submit").click(function () {                
            if ($('input[type="radio"]:checked').length == "0") {
                alert("Select any value");
            } else {
                $.ajax({
                    type: "POST",
                    url: "ajax-check.php",
                    data: $("#myform").serialize(),
                    success: function () {
                        $("#msg").addClass('bg');
                        $("#msg").html("value Entered");
                    }
                });
            }
            return false;
        });
    });
    

    After that, you can get the radio button values from the $_POST array in your PHP script:

    $_POST['q1'] // value of q1, can be 1-5
    $_POST['q2'] // value of q1, can be 1-5
    

    EDIT: The problem with your PHP code is that you used + instead of . for concatenating strings. Write this instead:

    $q[$i] = isset($_POST['q'.$i]) ? mysql_real_escape_string($_POST['q'.$i]) : 0;
    

    After this, I’m pretty sure it will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.