Storing data in a database with the use of JavaScript

Below is the code I am sharing, where data from a JavaScript file is stored in a MySQL database.

The code in the JavaScript file is:

 function set_shield(t_value){
           var ok = confirm("Are you sure want Lock Value?")
                                if (ok)
                                {
                                    xmlhttp.open("GET","p_scripts/dataStore.php?set_value="+shield.value,true);
                                    xmlhttp.send();
                                    window.location.reload(true);
                                    }                           
                        }

The code in my dataStore.php file is as follows:

 <?php
   session_start();
   $set_value=$_GET[set_value];
   include("php_scripts\db.php"); // connection create here
   $date =date("Y-m-d H:i:s");
   mysql_query("Update user SET p1='y' WHERE  user_id='$_SESSION[login_user]'");
   mysql_query("INSERT power_play (user_id, p_play_type, date_of_play, set_value) VALUES ('$_SESSION[login_user]','1','$date','$set_value')");

    ?>

Answer №1

It appears that your Insert query may not be formatted correctly. Give this a try:

INSERT INTO power_play (user_id, p_play_type, date_of_play, set_value)
    VALUES ('$_SESSION[login_user]', '1', '$date', '$set_value')");

Answer №2

Experiment with the following code snippet on the client side

let xhttp = new XMLHttpRequest();
xhttp.open("GET", queryScripts/storage.php?value="+protect.value,true);
xhttp.send();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error alert: Object expected on OnClientClick in Microsoft JScript runtime

I was in the middle of a quick test when I encountered an error. At this point, I haven't implemented any C# code yet and my aspx code looks like this: <script language=javascript type="text/javascript"> function myOnClick() { ...

Tips for getting rid of Next.js' default loading indicator

While working on my project using Next.js, I've noticed that whenever I change the route, a default loading indicator appears in the corner of the screen. https://i.sstatic.net/FVWEU.gif Does anyone know how to remove this default loading indicator ...

Rewriting URLs in Angular 2

I am a beginner in Angular 2 and I am currently working on a project that requires URL rewriting similar to that of ' '. In Zomato, when you select a city, the city name appears in the URL like ' ', and when you select a restaurant, t ...

PHP does not support mysqldump; it can only be used with the command line

Having Trouble Executing a PHP Command system ('mysqldump -u myUser myDbname | mysql -u myUser -A myDbBackupName'); Despite not receiving an error message, this command is not producing any results. Interestingly, when the same command is execu ...

Building a nested query in MySQL

I have a task to query for real estate agents who have listings under $500,000. The data I need includes their first name, last name, work phone, mobile phone, and email address. Table: listings Columns: listing_key int PK Agents_key int listing_status ...

React has reached the maximum update depth limit

In my current project, I am developing a react application that involves a user inputting a search term and receiving an array of JSON data from the backend. On the results page, I have been working on implementing faceted search, which includes several fi ...

How to update a nested object within an array in mongoose by referencing its specific id

Here is a glimpse of my database where I am looking to update an object within the perDayDetails array using its unique identifier in Mongoose. "_id":{"$oid":"612f45863106a21bc0506a36"}, "fullname":"abc xyz" ...

The initial click does not trigger a state update in React

I attempted to create a straightforward system for displaying data with two sorting buttons (ascending & descending). My approach involved fetching and displaying data from an array using the map method. In a separate component file, I utilized useEffect ...

Using a series of identical divs to dynamically update the image URL

Greetings! I am a newcomer to the world of web development and I have decided to hone my skills by creating a small website for my mother! My goal is to replicate a specific div multiple times while changing only the image URL and the heading caption. < ...

Error message indicates that there is an issue with an Angular Grid within an Angular widget: [$injector:unpr] Unknown provider

In this particular code snippet, I've developed an angular widget that utilizes an angular grid for data transmission. However, I seem to be encountering the following error message: Error: [$injector:unpr] Unknown provider: alphadataProvider <- al ...

Receive Real-Time Notifications -> Update Title Using an Array Retrieved from a JSON File

I've been working on updating a live chart every 5 seconds with new data from the database. While I could easily update the information, I encountered a problem when trying to set a path within the chart options for tooltips callbacks afterTitle. Spec ...

Tips for retrieving a value from an async function called within the .map function in React?

After doing some research, I discovered that async functions return a promise whose result value can be accessed using .then() after the function. This is the reason why it's not rendering properly. My question is: how can I render the actual value fr ...

Utilize Express.js to seamlessly stream and process uploaded files with formidable and gm, ensuring a streamlined process without

I am looking for a solution to upload and resize an image in one step without having to write to disk twice. For uploading images, I am using: node-formidable: https://github.com/felixge/node-formidable And for resizing the images, I am using: gm: Howev ...

Modify the `div` content based on the selected items from the bootstrap dropdown menu

My navigation bar is built using Bootstrap and contains multiple drop-down items. Now I have another div with the class of col-md-3. Within this div, I would like to display the items of the dropdown menu when hovered over. Currently, hovering over a dro ...

Error thrown: Upon attempting to reopen the modalbox after closing it, an uncaught TypeError is encountered, indicating that the function $(...).load

An unexpected error occurred: $(...).load(...).modal is not functioning properly After closing a modal, I encountered this error in the console when attempting to reopen it. Strangely, it seems to work intermittently for a few times before throwing this e ...

Optimizing normals for unindexed BufferGeometry in Three.js

Currently, I am attempting to refine the normals of a mesh starting from an non indexed BufferGeometry. A similar query has been addressed in the past, however, the Three.js API has undergone significant changes since then and I am unable to make it work o ...

Unable to utilize Socket.io version 2.0.3

When it comes to developing a video chat app, I decided to utilize socket.io. In order to familiarize myself with this library, I followed various tutorials, but unfortunately, I always encountered the same issue. Every time I attempted to invoke the libr ...

Is there a way to verify if the content shown for each child is distinct from the others?

it('features', () => { home.featuresMainTitle("What you'll learn") cy.get('.grid').children().each(($el, index, $list) =>{ const currentText = $el.find('h3').text() const nextText = $el.n ...

Firebase is currently experiencing issues with authenticating and removing onDisconnect() functionality

I am encountering issues with implementing onDisconnect().remove() in conjunction with authentication/security rules. Here is what I have set up: Initially, the user is logged in using auth(): var rootRef = new Firebase(FIREBASE_URL + 'sites/' ...

Is there a way to restrict the types of messages that users can set in Node.js?

I recently started developing a multiplayer game and made the decision to incorporate NodeJS into the system. NodeJS is connected to my C# game emulator via TCP. My current challenge is figuring out how to send messages to specific user IDs. Each user in ...