Tips for sending a MySQL parameter

Hey there, I need some help with the trigger setup I have:

CREATE TRIGGER `update` AFTER UPDATE ON `table 1` 
FOR EACH ROW INSERT INTO table 2 (
Id,
Revision,
Purpose,
Change
)
VALUES
(
OLD.Id,
OLD.Revision,
OLD.Purpose,
@purpose_change  /* user variable */
);

$$ DELIMITER ;

I'm working with C# WebService, Ajax, and JavaScript. Below are my C# methods for update (currently not functioning correctly)

"UPDATE table 1 SET Revision=@revision, Purpose=@purpose, @purpose_change=@change WHERE (Id =@id)";

The issue arises as I am unsure about how to send @purpose_channge properly.

Here's my Web Method.

[WebMethod(EnableSession = true)]
public string UpdateAlert(int id, string revision, string purpose, string change, int op)
{
    string response = "An Error Has Occurred.";
    try
    {
        UpdateAlert ua = new UpdateAlert(id, revision, purpose, change);

        int resp = conn.UpdateAlerta(ua, op);

        if (resp > 0)
            response = "Success!.";
    }
    catch (Exception ex)
    {
        response = "An Error Has Occurred: " + ex.Message;
    }
    return response;
}

And here's my JavaScript function with AJAX call.

 $.ajax({
    type: "POST",            
    url: urlServer + "ws_alerts.asmx/ActualizarAlerta",                      
    data: '{' +
        '"id":' + id +
        ',"revision":"' + rev +
        '","purpose":"' + pur +           
        '","change":"' + change +
        '","op":' + op + '}',      
    dataType: "json",              
    contentType: "application/json",        
    timeout: 60000,       
    error: function (xhr) {  
        bootbox.alert("An error occurred while processing the request.");
    },
    success: function (data) {
        bootbox.alert(data.d);
    }
});

id, rev, change, etc. values are retrieved using $('#MyId').val()

The main problem lies in the Update query but I am uncertain how to correct it. Any suggestions on what needs to be done?

Answer №1

If you are using a MySQL user variable, it is necessary to execute a raw query before calling the UpdateAlerta() function.

SqlCommand cmd = new SqlCommand("set @purpose_change = 'Purpose change to 1';", conn);
cmd.ExecuteNonQuery();

Just a reminder (I recall seeing another relevant post here)

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

Refreshing the session cookie during an ajax request in CodeIgniter

Here is the ajax call I am using: remote: { url:"http://localhost/my_site/index_page/validate_name", type: "post" } Within the validate_name function, I am setting the session cookie in this way: $username = "t ...

I am looking for a way to access an array from Node.js using JavaScript and EJS. How can I achieve this

Currently, I am developing an app that requires passing an array from the server to the client. Initially, I attempted the following: // Server app.get('/', (req,res) => { res.render('index', { data: ["Hello"] }) }) ...

Utilize Angular 2 interceptor to incorporate HTTP requests

Dealing with the 401 response from an interceptor using the HttpClientModule in Angular and JWT authentication can be a bit tricky. When the accessToken expires, it's necessary to use the refreshToken to obtain a new one before making the actual API r ...

`There is a lack of props validation in the react/prop-types``

As I set up my Next-React app on Netlify, I encountered an error in the deploy log: Netlify deploy log indicates: "Error: 'Component' is missing in props validation", "Error: 'pageProps' is missing in props validation" within my ./page ...

JavaScript code to dynamically change the minimum value of an input field when the page

How can I use JavaScript to change the minimum value onload? I tried the following code but it didn't work: <script type="text/javascript">$(document).ready(function(){ $("#quantity_5c27c535d66fc").min('10'); });</script> ...

"Exploring the interactivity of touch events on JavaScript

Hi there, I'm currently facing an issue with the touch events on my canvas. While the mouse events are functioning correctly and drawing as expected, incorporating touch events seems to be causing a problem. When I touch the canvas, the output remains ...

Using jQuery/Javascript to create a dynamic content slider

I am currently working on developing a straightforward content slider. When the page loads, my goal is to display only one item (including an image and some content) and provide a navigation system for users to move through the items. Below is the basic H ...

Instructions for selecting a checkbox using boolean values

According to the HTML specification, you should use the checked attribute in the <input type="checkbox"> tag to indicate that it is checked. However, I only have a boolean value of either true or false. Unfortunately, I am unable to manipulate the b ...

Encountering a 404 error when utilizing {{url()}} within Laravel's Ajax feature

Hello, I encountered an error while working with ajax on laravel. The console is showing a 404 error, here's my ajax code: $('#btn_search_postcode').click(function(e){ let postcode = $('#postcode').val(); if(postcod ...

Most effective method for showcasing the image once it has been successfully loaded

At the moment, I am considering two methods to display an image after it has been loaded. Initial Method <img id="myImage" /> var img = new Image(), x = document.getElementById("myImage"); img.onload = function() { x.src = img.src; }; img ...

Javascript Leap Year Determination using nested if-else statements

I am facing an issue with the nested if statement where all conditions have been provided. Some leap years like 2016 and 2020 are not being recognized as Leap years even though they should be. Can someone please assist me in fixing this error? var y = p ...

Creating a table with a static first column and vertical text positioned to the left of the fixed column

To create a table with the first column fixed, refer to this fiddle link: http://jsfiddle.net/Yw679/6/. You also need a vertical text to be positioned to the left of the fixed column in a way that it remains fixed like the first column. The disparities be ...

(Javascript) Extracting specific values from JSON objects using a loop

JSON: [ { "id": 1, "name": "One", "value": "Hello 1", "enabled": true, }, { "id": 2, "name": "Two", "value": "Hello 2", "e ...

When attempting to make a post using Prisma's ORM, users may encounter an error message indicating that the post function

Creating a basic prisma application using express and node to query a local mysql database. Encountering an error when calling await prisa.list.create(), details provided below. Here is the script.js code snippet from the HTML page: addItemForm.addEvent ...

The index "is_ajax" has not been defined

I attempted to create a simple login functionality using Ajax. Following a tutorial that didn't use classes and functions in PHP, I tried restructuring the code with classes and functions. However, I encountered the error: Undefined index: is_ajax He ...

Discover the steps to execute a continuous loop of animations on a singular component using framer-motion

I'm currently working on a website that incorporates framer-motion for animations One key component of the site is an image displayed as follows: <motion.img ref={scope} initial={{ x: -200 }} alt="pa ...

Issue with uploading media on Wordpress: "Unfortunately, an error occurred during the upload process. Please attempt again at a later time."

Often times, when trying to upload media from the front-end, I encounter this issue: An error occurred during the upload process It seems like the error occurs sporadically, making it even more challenging to troubleshoot. Sometimes, when logging in fo ...

Using special characters as parameters in Ajax requests

I need assistance with sending data via Ajax to my controller action. Here is the code snippet: $.ajax({ url: "/cotroller/action", data: { fieldsOfStudy: $('[name=fieldsOfStudy]').serialize()} }) The 'fieldsOfStudy' select bo ...

Encountering issues with browser tabs and Socket.IO

I'm currently working on a real-time chat using Socket.IO, but I've encountered a major issue. The aim is to allow users to log in, select another connected user, and start chatting... var http = require('http'), fs = require(&ap ...

How can I modify a GET request in Express to handle multiple tables or accommodate additional functionalities?

Seeking assistance for my final university project which I plan to develop using NodeJS, EJS, and MySQL. I am facing an error in the code snippet below and despite being new to this, I cannot seem to resolve it: connection.query('SELECT u.id_user ...