Passing value to php is undefined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cleary1981
    New Member
    • Jun 2008
    • 178

    #16
    No the value is assigned in showobject

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #17
      Yes, but g_objName is set in createObject() on line 197. Check that it's set properly there.

      Comment

      • cleary1981
        New Member
        • Jun 2008
        • 178

        #18
        It is working fine. I inserted an alert at the end of that function and it gave me the correct result. I also put the same alert at the start of the render function and that worked also.

        Comment

        • cleary1981
          New Member
          • Jun 2008
          • 178

          #19
          The values in the render funcion are all fine as I used the alerts as shown below and they all prduced the correct results. Does the problem lie in the php code.

          Code:
          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);
              	data['result[]'].push(arr[i].innerHTML);
              	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 code in question
          Code:
          <?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'");
          	
          }
          
          ?>
          config.php works fine as I have used it throughout this program

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #20
            So you're saying arr[i].innerHTML is no longer undefined?

            Comment

            • cleary1981
              New Member
              • Jun 2008
              • 178

              #21
              Yeah. Dont know whats changed but its working now. lol. Just doesnt update my db. Problem must be in the php

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #22
                Well, if the values passed are all fine and the call is OK, that just leaves the PHP code. Perhaps you should ask in the PHP forum.

                Comment

                • cleary1981
                  New Member
                  • Jun 2008
                  • 178

                  #23
                  OK will try that now. thanks.

                  Comment

                  • cleary1981
                    New Member
                    • Jun 2008
                    • 178

                    #24
                    Hi,

                    My php seems to be working fine now. I think. All the records are updating except for the very first one. Heres my code now.

                    Jquery
                    Code:
                    function render() {
                    	
                    	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 
                    }
                    php
                    Code:
                    <?php
                    require "config.php";
                    
                    
                    foreach($_POST['result'] as $n=>$result){
                       $xReturnValue = $_POST['xReturnValue'][$n];
                       $yReturnValue = $_POST['yReturnValue'][$n];
                       $q = mysql_query("UPDATE object SET xpos='$xReturnValue', ypos='$yReturnValue' WHERE object_name = '$result'");
                    }
                    
                    ?>

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #25
                      Does the first div display undefined or is it the name of the first object to be updated?

                      Comment

                      • cleary1981
                        New Member
                        • Jun 2008
                        • 178

                        #26
                        in the alerts it shows the correct information

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #27
                          OK, if you pass these same values in the same format to PHP without Ajax, does it (still not) work?

                          Comment

                          • cleary1981
                            New Member
                            • Jun 2008
                            • 178

                            #28
                            when i do that only random records get updated. I cant see any errors in any of the code. Cud this be a bug in mysql?

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #29
                              The query seems simple enough. How did the thread in the PHP forum go?

                              Comment

                              • cleary1981
                                New Member
                                • Jun 2008
                                • 178

                                #30
                                hadnt much luck with it. Im thinking of rewriting my script all together

                                Comment

                                Working...