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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:38:18+00:00 2026-06-13T20:38:18+00:00

I have looked at other questions and cannot find the answer to why this

  • 0

I have looked at other questions and cannot find the answer to why this isn’t working. I am following a tutorial online. Here is my code:

HTML file:

<!DOCTYPE HTML>
<html>
<head>
<title>AJAX Test</title>
</head>
<body>
<h4>Enter an Item</h4>
<input type="text" id="item" /><br />
<input type="button" id="button" value="Submit" /><br />
<div id="content"></div>
<script type="text/javascript" scr="ajax.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
</body>
</html>

JS file:

$('#button').click(function() {
var item = $('#item').val();

$('#content').text('Loading...');

$.post('ajax.php', { item: item }, function(data) {
    $('#content').text(data);
    });
});

PHP file:

<?php
include 'db.php';

if (isset($_POST['item'])) {
    $item = $_POST['item'];
    $sql = mysql_query("INSERT INTO items(item)VALUES('$item')");
    if ($sql === true) {
        echo "Inserted into database";
    } elseif ($sql ==== false) {
        echo "Error inserting into database";
    }
 }
 ?>

I don’t see what I’m doing wrong. The tutorial has the same code. Thanks for your help.

  • 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-13T20:38:20+00:00Added an answer on June 13, 2026 at 8:38 pm

    moonwave99 is right (I’m not sure why the downvotes).. and also the scr=”ajax” should be src=”ajax” in your html and should be put in head or even before. Other reason may be the position of ajax.php to the site, maybe declaring whole URL will help :

    $.post('http://wholeurl/ajax.php', { 
          item: item 
       }, function(data) {
          $('#content').text(data);
       });
    

    Hope this helps, if not please specify error.

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

Sidebar

Related Questions

I have looked all over and cannot figure out why this code isn't working.
Just to make this clear, I have looked at the other questions on this
I have looked for similar questions, but could find none other than the difference
I've looked through several other questions here and on other sites regarding this issue,
I have looked at the other questions on SO and I cannot seem to
I have looked at other questions and online but still cant figure out where
Have looked quite hard for this answer but having no luck. I have 3
I have looked at questions like this , this , this and this ,
I have looked around on Google and StackOverflow for the answer to this question,
I looked at some other SO questions, didn't find anything that solved my problem...

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.