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 8705341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:20:14+00:00 2026-06-13T03:20:14+00:00

I was try to post from Ajax to PHP file to build poll system

  • 0

I was try to post from Ajax to PHP file to build poll system but I can’t send any request because I can’t see radio button…Something wrong with cookie check…what I just want to check user IP if he already vote disappear radio buttons, if not he display radio buttons

index.html

    <script type="text/javascript" >
        $(function(){
            var loader=$('#loader');
            var pollcontainer=$('#pollcontainer');
            loader.fadeIn();
            //Load the poll form
            $.get('poll.php', '', function(data, status){
                pollcontainer.html(data);
                animateResults(pollcontainer);
                pollcontainer.find('#viewresult').click(function(){
                    //if user wants to see result
                    loader.fadeIn();
                    $.get('poll.php', 'result=1', function(data,status){
                        pollcontainer.fadeOut(1000, function(){
                            $(this).html(data);
                            animateResults(this);
                        });
                        loader.fadeOut();
                    });
                    //prevent default behavior
                    return false;
                }).end()
                .find('#pollform').submit(function(){
                    var selected_val=$(this).find('input[name=poll]:checked').val();
                    if(selected_val!=''){
                        //post data only if a value is selected
                        loader.fadeIn();
                        $.post('poll.php', $(this).serialize(), function(data, status){
                            $('#formcontainer').fadeOut(100, function(){
                                $(this).html(data);
                                animateResults(this);
                                loader.fadeOut();
                            });
                        });
                    }
                    //prevent form default behavior
                    return false;
                });
                loader.fadeOut();
            });

            function animateResults(data){
                $(data).find('.bar').hide().end().fadeIn('slow', function(){
                    $(this).find('.bar').each(function(){
                        var bar_width=$(this).css('width');
                        $(this).css('width', '0').animate({ width: bar_width }, 1000);
                    });
                });
            }

        });
    </script>

poll.php

if (!isset($_POST['poll']) || !isset($_POST['pollid'])) {
    $query = mysql_query("SELECT id, ques FROM questions ORDER BY id DESC LIMIT 1");
    while ($row = mysql_fetch_assoc($query)) {
        //display question
        echo "<p class=\"pollques\" >" . $row['ques'] . "</p>";
        $poll_id = $row['id'];
    }
    if (isset($_GET["result"]) == 1 || isset($_COOKIE["voted" . $poll_id]) == 'yes') {
        //if already voted or asked for result
        showresults($poll_id);
        exit;
    } else {
        //display options with radio buttons
        $query = mysql_query("SELECT id, value FROM options WHERE ques_id=$poll_id");
        if (mysql_num_rows($query)) {
            echo '<div id="formcontainer" ><form method="post" id="pollform" action="' . $_SERVER['PHP_SELF'] . '" >';
            echo '<input type="hidden" name="pollid" value="' . $poll_id . '" />';
            while ($row = mysql_fetch_assoc($query)) {
                echo '<p><input type="radio" name="poll" value="' . $row['id'] . '" id="option-' . $row['id'] . '" /> 
                <label for="option-' . $row['id'] . '" >' . $row['value'] . '</label></p>';
            }
            echo '<p><input type="submit"  value="Submit" /></p></form>';
            echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?result=1" id="viewresult">View result</a></p></div>';
        }
    }
} else {
    // i cant see this radio 
    if (isset($_COOKIE["voted" . $_POST['pollid']]) != 'yes') {

        //Check if selected option value is there in database?
        $query = mysql_query("SELECT * FROM options WHERE id='" . intval($_POST["poll"]) . "'");
        if (mysql_num_rows($query)) {
            $query = "INSERT INTO votes(option_id, voted_on, ip) VALUES('" . $_POST["poll"] . "', '" . date('Y-m-d H:i:s') . "', '" . $_SERVER['REMOTE_ADDR'] . "')";
            if (mysql_query($query)) {
                //Vote added to database
                setcookie("voted" . $_POST['pollid'], 'yes', time() + 86400 * 300);
            }
            else
                echo "There was some error processing the query: " . mysql_error();
        }
    }
    showresults(intval($_POST['pollid']));
}
  • 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-13T03:20:15+00:00Added an answer on June 13, 2026 at 3:20 am

    isset($_COOKIE["voted" . $poll_id]) == 'yes' isset returns true or false, so this condition is always false.
    same with this if (isset($_COOKIE["voted" . $_POST['pollid']]) != 'yes')

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

Sidebar

Related Questions

When I try to get the response from a php file using Jquery ajax,
I try to send a variable using jquery and ajax to php script. Then
I try to post the values from the input field with the jquery.ajax function
First I try'd doing it with Mail_mime from Pear, but I can't load the
I try searching about this but I just can't find any that can solve
i have one AJAX function getting results from php file as bellow $.ajax({ type:
I try to write a Jquery. Ajax in codeigniter. But it does not post
HttpRequestValidationException occurs when I try post when txtBulletin contains any HTML, like Hello<br />World
i try to post data by ajax , it gives me name value bu
I am using the PHP SDK to try and post a simple action using

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.