views:

17

answers:

2

dear all.. i'm newbie,i want change my DB data from jquery-ui dialog. What code should I add to the dialog script that can make me connecting to process page before connecting to DB?

A: 

I am not sure you understand the question you are asking. Javascript can't directly modify data on your server, it needs to invoke a PHP, C#, Perl or other script on the server by passing data to it. This server-side script then modifies your database.

If it were PHP your Javascript might make a POST request containing:

name=Dave&phone_number=12345

Your PHP script would then use $_POST['name'] and $_POST['phone_number'] to access that data and send it to the database. I would recommend some background reading such as: Dynamic-Application-Development-Using-MySQ or Web-Application-Architecture-Principles-Protocols or PHP-MySQL-Dynamic-Web-Sites and jQuery in action

Aiden Bell
A: 

In your jquery-ui dialog you should have let say a button, and when you press it, it would update a row in a database table. In order to do it:

-Create a button, and when pressed it would trigger an ajax request to a php file:

$('#MyButton').click(function() {
 $.ajax({
 type: "GET",
 url: "MyPage.php",
 data: "id=3",
 cache: false,
 error: function (msg) {},
 success: function (msg) {}
 });
});

-In your php file you would have a script updating the row in the database table:

<?php
mysql_connect("Host", "Login", "Password) OR trigger_error(mysql_error(), E_USER_ERROR);
mysql_select_db("DatabaseName") OR trigger_error(mysql_error(), E_USER_ERROR);
mysql_query("UPDATE tableName SET myValue = 'value' WHERE condition = 'value'") OR trigger_error($query, E_USER_ERROR);
?>

This is a really simple example, I would recommend reading the following tutorials:

http://php4every1.com/tutorials/jquery-ajax-tutorial/

Lobsterm
-1: Sometimes it is better to give generic advice and pointers, rather than encourage dangerous practice due to the restrictions in answer brevity.
Aiden Bell
I do not see any security issue, except the fact that anyone could call the php script, which modify the same value over and over. The only dangerous thing would be an attacker who would call this script over and over and would saturate the server. I'll take your advice tho :) thanks!
Lobsterm