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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:07:39+00:00 2026-06-03T08:07:39+00:00

I am having some trouble with my jquery. I am not sure if it

  • 0

I am having some trouble with my jquery. I am not sure if it is connecting to doc.php but I am not getting anything inserted into my database.

I have an insert command in doc.php which I know is working.

I’m trying to create a way to update prices in a database, from doc.php, that searches out items one at a time.

The doc.php is searching by var, then updating in the same page.

The foreach loop function then, takes the var one by one, sends them to the doc.php page that then searches by var and updates into the database.

<?php

mysql_connect("", "", "") or die(mysql_error());

mysql_select_db("") or die (mysql_error());


$sql = "SELECT var FROM table";
$query = mysql_query($sql) or die (mysql_error());
while ($result = mysql_fetch_array($query)) {


$variable = array($result['var']);

foreach ($variable as $variable1) {


?>
<script src="jquery-1.7.2.min.js" type="text/javascript">

$(function() {
    var valueToSend = '<?php echo $variable1; ?>';

$.ajax({
    url: "doc.php",
    dataType: "json",
    type: "POST",
    data: { Variable: valueToSend },
    success: function (m) {
        alert(m);
    },
    error: function (e) {
      alert("Something went wrong ...: "+e.message);
    },
  }); /* end ajax*/
  e.preventDefault();
});
</script>

<?php


}


}

?>
  • 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-03T08:07:40+00:00Added an answer on June 3, 2026 at 8:07 am

    First of all, what do you want to do with this code? If you want to read & write to db using php, ajax call is unnecessary. If you want to practice ajax & php you need to read some howto because your code is somewhere strange ;). This is nice collection of tutorials for jQuery and some for PHP read some and practice.

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

Sidebar

Related Questions

I'm working on a jQuery plugin, but am having some trouble getting my variables
I'm having trouble getting some javascript and Jquery to delay the appropriate amount of
I'm having some trouble with detecting a jQuery ajax request with PHP on a
I'm having some trouble getting jquery to post some json data to a rest
I am having some trouble with getting jquery to recognize classes/ids of content that
I'm implementing a class-like structure in jQuery, but I'm having some trouble when I
I am working on a jQuery plugin, but I am having some trouble with
I'm having some trouble with the jQuery hover method. Here's the relevant JavaScript code:
I'm having some trouble with finding the visibility param for JQuery. Basically... the code
I am having some trouble setting up FancyBox, I am somewhat new to jQuery.

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.