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

  • Home
  • SEARCH
  • 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 9116225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:37:15+00:00 2026-06-17T04:37:15+00:00

This is php page which echoes variable $correct . Its initial value is 0

  • 0

This is php page which echoes variable $correct. Its initial value is 0. It is changing with increment in its value but when i load this value after echoing it to other page using jquery ajax method it returns only 0 not the increment value.

<?php

$i=1;
while($i<=10) {

    $answer="answer_".$i;
    ${"answer_$i"}=$_POST[$answer];
    $i++;
}

$correct=0;

if($answer_1=="a")
$correct=$correct+10;
else {
    if($answer_1=="b" || $answer_1=="c" || $answer_1=="d")
        $correct=$correct-10;

}
if($answer_2=="a")
$correct=$correct+10;
else {
if($answer_2=="b" || $answer_2=="c" || $answer_2=="d")
            $correct=$correct-10;
}
if($answer_3=="a")
$correct=$correct+10;
else {
    if($answer_3=="b" || $answer_3=="c" || $answer_3=="d")
        $correct=$correct-10;
}
if($answer_4=="a")
$correct=$correct+10;
else
{   if($answer_4=="b" || $answer_4=="c" || $answer_4=="d")
        $correct=$correct-10;
}
if($answer_5=="a")
$correct=$correct+10;
else
{   if($answer_5=="b" || $answer_5=="c" || $answer_5=="d")
        $correct=$correct-10;
}
if($answer_6=="a")
$correct=$correct+10;
else
{   if($answer_6=="b" || $answer_6=="c" || $answer_6=="d")
        $correct=$correct-10;
}
if($answer_7=="a")
$correct=$correct+10;
else
{   if($answer_7=="b" || $answer_7=="c" || $answer_7=="d")
        $correct=$correct-10;
}
if($answer_8=="a")
$correct=$correct+10;
else {
    if($answer_8=="b" || $answer_8=="c" || $answer_8=="d")
        $correct=$correct-10;
}
if($answer_9=="a")
$correct=$correct+10;
else
{
    if($answer_9=="b" || $answer_9=="c" || $answer_9=="d")
        $correct=$correct-10;
}
if($answer_10=="a")
$correct=$correct+10;
else
{
    if($answer_10=="b" || $answer_10=="c" || $answer_10=="d")
        $correct=$correct-10;
}
echo "$correct";
?>

This is script on other page which access this variable $correct but it always result in 0,though the variable value is changing on the php page? How can i correct this?

<script>
$(function(){
$('form').submit(function(event){
event.preventDefault();
$.ajax({
url:"results.php",
type:"POST",
success:function(result){
console.log(result);
$('#results').html("<p>"+result+"</p>");
}
});
});
});
</script>               
  • 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-17T04:37:16+00:00Added an answer on June 17, 2026 at 4:37 am

    You’re not passing any answers from AJAX to PHP.
    Therefore none of your conditions in the PHP are met.
    Thus it returns 0.

    To pass data with the post request consult the ajax documentation (http://api.jquery.com/jQuery.ajax/). You’ll want to look at the data attribute.

    You’ll want to have something like this:

    $.ajax({
        url:"results.php",
        type:"POST",
        data: {
            answer_1: 'blue'    // what colour is the sky?
        },
        success:function(result){
            console.log(result);
            $('#results').html("<p>"+result+"</p>");
        }
    });
    

    Then your PHP needs to collect the data but I imagine you already have that setup:

    $answer1 = $_POST['answer1'];
    

    Update:
    to include example information from user comment.

    <input type="radio" name="answer_1" value="a" id="question_1_answer_a"/> 
    <label for="question_1_answer_a">anirudh</label> 
    <input type="radio" name="answer_1" value="b" id="question_1_answer_b"/> 
    <label for="question_1_answer_b">anirudh</label>
    

    So you’d want something like this:

    data: {
        answer_1: $('input[name="answer_1"]').val(),    // from HTML example
        answer_2: $('input[name="answer_2"]').val(),
        answer_3: $('input[name="answer_3"]').val()
        // etc
    },
    

    If you’re not planning on modifying any of the form data with jQuery you could always just serialize it and post that instead: http://api.jquery.com/serialize/

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

Sidebar

Related Questions

I found this random page script which is in PHP file. I'm a bit
i have tried this code to redirect a php page.but it s not working
i have this simple code to load data from other php page using get
I created a php page which print this from the database [{sha_id:2,sha_text:This is 1st
I have a php page. This has multiple images which looks like tabs. With
I have this PHP page where the user can select and un-select items. The
Can anyone help in this php page navigation script switch on counting normal serial
Can anyone help me with reversing this PHP page navigation? Current script setting shows
I recently saw this page: PHP cli command line safe_mode restriction Where it is
The php.net page here http://www.php.net/manual/en/mysqlinfo.library.choosing.php says this Configure commands for using mysqlnd // Recommended,

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.