0

The question should be clear, but I'll explain once more: I'm trying to insert the individual values from an array in a mysql database.

Here is the code:

public function addRoute($pointArray){

    $length = 4; //just to be sure that nothing went wrong with calulating the length

    for($i = 0; $i < $length; $i++){

        $result = "INSERT into route_point(latlng, routeID) VALUES (4849, 10)"; //sample values, to once again be sure that there is nothing wrong with the values
        mysql_query($result);
    }

    mysql_close(); //just to be sure again
    return true;
}

The pointArray is being passed from actionscript using the zendamf framework if anyone is wondering. In my eyes nothing is wrong with the statement, but instead of inserting 4 rows, it inserts more than 100 000 rows.. I also don't receive the "true" back in actionscript, which should be passed when the php function is executed.

I also tried a for each loop, but I get an error (which I can't read since i'm calling the php file from actionscript).

foreach ($pointArray as $value) {

        $result = "INSERT into route_point(latlng, routeID) VALUES ('$value', 10)";
        mysql_query($result);

    }

I prefer to use a for loop though.

Absolutely clueless on this, fiddled with several settings for a couple of hours now.

2
  • Actionscript doesn't support "sparse" arrays for output. If you do arr[500] = 1 in AS, and then send it out via AMF or JSON or whatever, the output data will be built with array elements 1 through 499 defined as well, not just #500, so you're sending 500 elements, not 1. Commented Dec 25, 2010 at 4:37
  • I've been able to see PHP errors through zendamf by using the Network tab of Chrome's developer tools. It helps to run $server->setProduction(!DEBUG) on the Zend_Amf_Server instance. Commented Aug 14, 2012 at 19:18

1 Answer 1

0

Are you sure addRoute is only called once? And the PHP file is called only once? I would ask what's in $pointArray but that doesn't really matter in this case =)

You could put a log in the addRoute function (write to file $file=microtime(1).'.log' to see how often it's called. You could build the log contents (of every addRoute call) in the for loop:

public function addRoute($pointArray){

$length = 4; 
//just to be sure that nothing went wrong with calulating the length

$log = '';
for($i = 0; $i &lt; $length; $i++){

    $log .= $i."\n"

    $result = "INSERT into route_point(latlng, routeID) VALUES (4849, 10)"; 
    //sample values, 
    //to once again be sure that there is nothing wrong with the values
    mysql_query($result);
}

file_put_contents(microtime(1).'.log', $log);

mysql_close(); //just to be sure again
return true;
}

And then see what really happened =)

3
  • Thanks! The error is resolved, I have no idea how but it suddenly worked o_O Things it had to do with the conversion between actionscript array and php array.. Anyway, the next problem is that in the loop, sending $pointArray[$i] returns an error ("INSERT into route_point(latlng) VALUES ('$pointArray[$i]')"). It works perfectly fine using $pointArray[0], something is wrong with the $i part. Commented Dec 25, 2010 at 0:41
  • You might want to add the result from mysql_error() to the log too. And even better: learn to use a debugger (Xdebug or such). es the can be combined with such services Commented Dec 25, 2010 at 0:43
  • I'll take a look. Not being able to see the specific error message is very annoying. Commented Dec 25, 2010 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.