[Solved] Change database value [closed]


you can use xmlhttprequest, and the javascript :

var xhr = new XMLHttpRequest(); // Create new XHR
var url="http://sample.com/change.php"; // The url
var data="data=sample&back=come";
xhr.open('POST', url, true); // POST is method you can with `POST|GET`
xhr.send(data);

or it can be simplifer with jquery

var url="http://sample.com/change.php"; // The url
var data="data=sample&back=come";
$.post(url,data,function(callback){
  alert(callback);
});

and sure bind it on your image:

$("img").click(function(){
    var url="http://sample.com/change.php"; // The url
    var data="data=sample&back=come";
    $.post(url,data,function(callback){
     alert(callback);
    });
});

then the php file:

<?php
$post_data = mysql_real_escape_string($_POST['data']);
$post_back = mysql_real_escape_string($_POST['back']);
$query = mysql_query("UPDATE table SET data="".$post_data."" WHERE `back` = '".$post_back."'"); // This is a query, change it with yours
if($query){echo'Success';} //Print a success message
?>

Finish, good luck

3

solved Change database value [closed]