javascript - Parse JS value into MySQL DB -


I have a script that keeps track of the location of certain images by updating a variable in Javascript. However, I need to parse that value in DB so that the next time a user can login. My JS code is below: (house_positions.js)

  $ (document). (Function () {$ (". Item"). Draggable ({prevention: '# home_valva 1', drag: function () {var offset = $ (this) .offset (); var xPos = offset text ('y : '+ Ypos);}, search // (' y: '+ ypos'); $ ('x:' + xPos); $ ('# pos'). ("Div # start"). Start: "\ N Left:" + Startpos.left + "\ nTop:" + Startpos.top);}, find the position where the image has been dropped. Stop: function (Event, UI) {// Show status Close. Var Stoppos = $ (This) .position (); $ ("div # stop"). Text ("Pause: \ n Left:" + Stoppage. Left + "\ nTop:" + Stoppos.top) ;}}};});  

And then I have a MySQL database call:

   

As you can see, I have tried to insert the "Expos" variable from javascript into MySQL statement in PHP. I did not believe this would work, but well. Can anyone tell me how is this possible? thank you in advanced.

Update: My Ajax Code:

  Function HouseAjak () {var xmlhttp; If (window.XMLHttpRequest) {// code for IE7 +, Firefox, Chrome, Opera, Safari xmlhttp = New XMLHttpRequest (); } Else {// code for IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); } Xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate == 4 & xmlhttp.status == 200} {$ .post ("update_house.php.asp", {window.newx: xPos, window. Newy : YPos}, function (result) {});}} Xmlhttp.open ("POST", "update_house.php", true); xmlhttp.send ();}  

You're doing it a bit wrong, when you update your DB, the PHP function calls your parameters in JavaScript code Your PHP has to be transferred in. Before you do that your PHP does not know it.

Javascript Example:

  $. Post ("http://www.pbpixels.com/x/update_house.php", {newx: xPos, newy: YPos}, function (results) { // data has been updated});  

Wherever you hold the AJAX request in your server side php page, just get it from the call:

PHP: NewX = $ _POST ['New']; New = $ _POST ['New'];

And now call update function:

  if ($ stmt = $ mysqli-> Prepare ('UPDATE home_room1 SET x = newX, y = 

good luck

>

Comments