cleary1981 Posted August 13, 2008 Share Posted August 13, 2008 Hi All Im not so good with php, useless in fact. Im using jquery to pass an array to php. The php script should update records in a mysql db. The variables are all working in the javascript side but the records are not getting updated. Ive included the jquery function I am using just to make things a little clearer function render() { alert(g_objName); var arr = document.getElementsByTagName("div"); var data = { 'result[]' : [], 'xReturnValue[]': [], 'yReturnValue[]' : [] }; for(var i = 0; i < arr.length; i++) { var xReturnValue = -10; var yReturnValue = -5; for(var elem = arr[i];elem != null;elem = elem.offsetParent) { xReturnValue += elem.offsetLeft; yReturnValue += elem.offsetTop; } alert(arr[i].innerHTML); var result = arr[i].innerHTML; data['result[]'].push(result); data['xReturnValue[]'].push(xReturnValue); alert(xReturnValue); data['yReturnValue[]'].push(yReturnValue); alert(yReturnValue); } $.post("render.php",data); // this bit of code is using jquery } heres the php <?php require "config.php"; foreach($_POST['result'] as $n=>$result){ $xReturnValue = $_POST['xReturnValue'][$n]; $yReturnValue = $_POST['yReturnValue'][$n]; //do what you want with the data $q = mysql_query("update object set xpos='$xReturnValue', ypos='$yReturnValue' where object_name = '$result'"); } ?> Link to comment https://forums.phpfreaks.com/topic/119447-php-script-not-doing-anything/ Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 shouldn't you first check if post data has been submitted before just rolling it out <?php require "config.php"; if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'GET') { foreach($_POST['result'] as $n=>$result){ $xReturnValue = $_POST['xReturnValue'][$n]; $yReturnValue = $_POST['yReturnValue'][$n]; //do what you want with the data $q = mysql_query("update object set xpos='$xReturnValue', ypos='$yReturnValue' where object_name = '$result'"); } } ?> also try to debug using: print_r($_POST); Link to comment https://forums.phpfreaks.com/topic/119447-php-script-not-doing-anything/#findComment-615338 Share on other sites More sharing options...
cleary1981 Posted August 13, 2008 Author Share Posted August 13, 2008 where do i put that line to debug? Link to comment https://forums.phpfreaks.com/topic/119447-php-script-not-doing-anything/#findComment-615515 Share on other sites More sharing options...
cleary1981 Posted August 14, 2008 Author Share Posted August 14, 2008 Can anyone else shed some light on this problem please? Link to comment https://forums.phpfreaks.com/topic/119447-php-script-not-doing-anything/#findComment-616255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.