I’m sending some data through to a mysql server via android in an attempt to update some details. Currently the php side looks something like
this:
for($i=0; $i<(10); $i++){
for($k=0; $k<(10); $k++){
mysql_query("UPDATE sometable SET data_".$i."_".$k." = '10'
WHERE id = '".$_REQUEST['id']."'");
}
}
I have to use a loop becuase I’ll be building up lots of generic types of data with the style “data_x”. Unfortunately, this layout doesn’t
seem to update any fields in the database.
Does this method create some type of space, or just simply disrupt a complete variable when read in a statement?
Thanks
Ok, couple of things about current iteration.
`$res = mysql_query( $query ); if( !$res ) log( myslq_error() );/* or die or whatever */`
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:
Rewrite it with the dollar sign: