Dragging and dropping and on the drop event I’m supposed to be posting data to my php file, which then inserts it into a database. However it doesn’t work the way I expected from the documentation. And the whole cross language debugging has me wanting to just shut the laptop and go play with my dog… while I’m sure the dog would appreciate that, He’s the only one who would be benefiting. So I would really appreciate some sort of direction…
The full jquery is here, specific post function at the bottom:
[php] $(window).load(function(){
$(".make-draggable, .draggable, .drag").draggable({
helper: “clone”,
snap: “.draggable”,
snapMode: “inner”
});
$(".draggable").droppable({
drop: function(event, ui) {
var elemText = ui.draggable.text();
$(this).html(elemText);
var outB = ui.draggable.attr(‘id’).split("-");
var pl1;
var pl2;
if (outB[0] == “go”) {
var num = outB.length;
var loser;
var loserval;
var losloc;
var losid = outB[1];
var numchars = outB[1].length;
if (num === 2) {
var i = 1;
loser = (losid.charAt(0) + “-”);
pl1 = elemText;
for (i = 1; i < numchars; i++) {
loser = (loser+losid.charAt(i));
}
loserval = $("#go-" + loser);
losloc = ("#"+losid);
$(losloc).html(loserval.text());
pl2 = loserval.text();
} else if (num === 3) {
loser = (outB[1] + outB[2]);
loserval = $("#go-" + loser);
losloc = ("#"+loser);
$(losloc).html(loserval.text());
pl1 = loserval.text();
pl2 = elemText;
}
} else {
var getround = $(this).attr(‘id’);
if (getround == ‘round-final’) {
pl1 = $(’#winnerb’).text();
pl2 = $(’#loserb’).text();
} else {
var inti = getround.substring(1);
if (inti%2 == 0) {
pl1 = $(‘l’+(inti+1));
pl2 = elemText;
} else {
pl1 = elemText;
pl2 = $(‘l’+(inti+1));
}
}
}
var matrou = $(this).parent().attr(“id”).split("-");
$.urlParam = function(name){
var results = new RegExp(’[\?&]’ + name + ‘=([^&#]*)’).exec(window.location.href);
return results[1] || 0;
}
$.post(“sub_match.php”, {win: elemText, p1: pl1, p2: pl2, match: matrou[4], round: matrou[2], wloc: $(this).id, lloc: losloc, tid: $.urlParam(‘tid’)});
}
});
});[/php]
with sub_match.php to follow:
[php]<?php
session_start();
require(“goodies.php”);
$tid = clean($_REQUEST[‘tid’]);
$round = clean($_REQUEST[‘round’]);
$match = clean($_REQUEST[‘match’]);
$player1 = clean($_REQUEST[‘p1’]);
$player2 = clean($_REQUEST[‘p2’]);
$winner = clean($_REQUEST[‘win’]);
$wdest = clean($_REQUEST[‘wloc’]);
$ldest = clean($_REQUEST[‘lloc’]);
$query = (“INSERT INTO matches (id, tid, season, round, match, player1, player2, winner, wdest, ldest) VALUES (’’, '” . $tid . “’, '” . $season . “’, '” . $round . “’, '” . $match . “’, '” . $player1 . “’, '” . $player2 . “’, '” . $winner . “’, '” . $wdest . “’, '” . $ldest . “’, )”);
mysql_query($query);
?>[/php]
I really never have liked anything about javascript except for this first time in my life where I feel for this project I just have to have this. So any help/direction greatly appreciated.