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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:16:32+00:00 2026-06-10T13:16:32+00:00

i am calling a php page res.php using jquery and ajax. The code is:-

  • 0

i am calling a php page res.php using jquery and ajax. The code is:-

$('#submit_button').click(function () {        
    buildingVal = $("#building");
    levelVal = $("#level");
    data = 'building=' + buildingVal.val() + 'level=' + levelVal.val();
    $.ajax( {

        url: "res.php", 
        type: "POST",
        data: data,     
        success: function (data) {
            $('#npc').html(data);
        }
    });​
});

the res.php page codes are:-

<?php
//connect to the database
$con = mysql_connect("localhost","root","12345") or die("error ".mysql_error());

//connect to the travian table
mysql_select_db("trav",$con) or die("error ".mysql_error());

$building = mysql_real_escape_string($_GET['building']);
$level = mysql_real_escape_string($_GET['level']);


$query = "select * from ";
$query = $query . $building;
$query = $query . "where lvl=" . $level;
$query = $query . ";";
$result = mysql_query($query) or die('Error in Child Table!');

$data = mysql_fetch_assoc($result);

echo '<table><tr><td>Lumber=$data["lumber"]</td><td>Clay=$data["clay"]</td><td>Iron=$data["iron"]</td><td>Crop=$data["crop"]</td>';

?>

I am receiving the error

Notice: Undefined index: building in C:\xampp\htdocs\debal\res.php on line 8

Notice: Undefined index: level in C:\xampp\htdocs\debal\res.php on line 9
Error in Child Table!

How am i to extract both the parameters that were sent to the page and use them in the sql query to retrieve the data from the table in the database.
Please could you help me..

  • 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-10T13:16:34+00:00Added an answer on June 10, 2026 at 1:16 pm

    The problem is you are sending $_POST values through AJAX and trying to assign variables from $_GET on your res.php page. Change either AJAX function to type: "GET", or

    $building = mysql_real_escape_string($_POST['building']);
    $level = mysql_real_escape_string($_POST['level']);
    

    on res.php

    also you’re not sending the ‘level’ variable properly, you’re missing an ‘&’

    data = 'building=' + buildingVal.val() + '&level=' + levelVal.val();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jquery I am calling a php page using an ajax call. I call
I am calling a php function using ajax call but its not working. I
I have a PHP script that I'm calling with the .post() function in jQuery.
i'm calling the search.php page via ajax to search.html. the problem is, since i've
One part of my page is being loaded via ajax using jquery. For example
I have couple of forms on my php page. I am using jQuery (&
I want to select a particular Div after calling a php using $.ajax: my
I have a script that calls a php page via jquery/ajax. The results would
This is my php code to check how many time the page is calling.
I am calling a very simple PHP page with some equally simple AJAX, but

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.