Ok, couple of things about current iteration.
- Log/output your errors!
`$res = mysql_query( $query ); if( !$res ) log( myslq_error() );/* or die or whatever */`
- Do one update, not 100.
$query = "UPDATE sometable SET";
for($i=0; $i<(10); $i++){
for($k=0; $k<(10); $k++){
$query .= ' data_'.$i.'_'.$k.' = \'10\''
if( !( $k == $i && $i == 10 ) ) $query .= ',';
}
}
//see side note below
$query .= 'WHERE id = ' . mysql_real_escape_string( $_REQUEST['id'] );
$res = mysql_query( $query );
if( !$res ) do_something_with_error( mysql_error() );
100 updates can make your database/PHP angry and the last thing you want is an angry database. Further, this only does one array lookup in REQUEST, whereas the code above does 100. (O(1) * 100 is still 100).
As a side note: just because something is supposed to be sent from Android, that is no reason to expect that it does not need to be properly escaped. Remember the lessons of Bobby Tables!
I also cannot suggest strongly enough that you reconsider your schema. That may seem to be the easiest way to handle things right now, but later developers (including yourself) will wonder what the heck was supposed to be stored there. I've worked on projects like that and they were not fun. (On the other hand, I don't know your specifics, so I could be completely wrong).
This was addressing an initial copy paste error:
At a bare minimum, PHP can't parse this line:
for(ik=0; $i<(10); $i++)
Rewrite it with the dollar sign:
for($i=0; $i<(10); $i++)
$iis even set? Have you checked whether you're getting any sort of errors from MySQL seeing you construct field names dynamically for querying? Where's your WHERE clause? Why don't you post entire code? It's not cool to guess around what might be wrong by seeing half the puzzle.mysql_error(), you're not cleaning$_REQUEST['id']and worst of all you're issuing 100 queries to update a single record.. that kind of isn't how it's supposed to be done (plus a table with 100 columns smells like something bad happened to db schema). So, you can do the mentioned - check for errors withmysql_error(), ensure you have the fields in the table and clean your $_REQUEST['id'] - then we can take it from there if it still doesn't work.