php - Function expects array to be string, convert? -
before downvoting can atleast write bothering you, jesus christ arogance
i "warning: mysql_real_escape_string() expects parameter 1 string, array given in bla bla..." everytime following happens:
if($_post['action'] == 'napadi') { $igralec_ime = $_session['username']; $igralec = array ( 'ime' => $igralec_ime, 'napad' => prikazi_stat('ofe',$igralec_ime), 'obramba' => prikazi_stat('def',$igralec_ime), 'curhp' => prikazi_stat('curhp',$igralec_ime) ); $monster_ime = $_post['monster']; $monster = array ( 'ime' => $monster_ime, 'napad' => prikazi_monster_stat('ofe',$monster_ime), 'obramba' => prikazi_monster_stat('def',$monster_ime), 'curhp' => prikazi_monster_stat('maxhp',$monster_ime) ); $combat = array(); $turns = 0; while($igralec['curhp'] > 0 && $monster['curhp'] > 0) { if($turns % 2 != 0) { $napadalec = &$monster; $branilec = &$igralec; } else { $napadalec = &$igralec; $branilec = &$monster; } $damage = 0; if($napadalec['napad'] > $branilec['obramba']) { $damage = $napadalec['napad'] - $branilec['obramba']; } $branilec['curhp'] -= $damage; $combat[$turns] = array( 'napadalec' => $napadalec['ime'], 'branilec' => $branilec['ime'], 'damage' => $damage ) $turns++; } $_session['monster'] = $monster;
above code puts variable $monster in array can see, when page redirects view page , tries update function update_save($igralec_ime, 'gozd', $monster);
above warning. know because page returns bunch of monster variables so:
matic napade velikanski komar in mu napravi poškodbe za 2 točk zdravja velikanski komar napade matic in mu napravi poškodbe za 1 točk zdravja matic napade velikanski komar in mu napravi poškodbe za 2 točk zdravja velikanski komar napade matic in mu napravi poškodbe za 1 točk zdravja
etc... don't know how fix it. should convert outputed array sring?
edit: code problematic function
function update_save($igralec_name, $lokacija, $monster_name = null) { ustvari_save($igralec_name, $lokacija, $monster_name); $query = sprintf("update igralec_save set lokacija = '%s', monster_name = '%s' igralec_name = '%s'", mysql_real_escape_string($lokacija), mysql_real_escape_string($monster_name), mysql_real_escape_string($igralec_name)); $result = mysql_query($query); }
if $monster
array , mysql_real_escape_string
name implies, takes string, must pass string.
since function takes $monster_name
, perhaps need take $monster
array?
something (without idea of code, example, not copy , paste :) ):
update_save($igralec_ime, 'gozd', $monster['ime']);
Comments
Post a Comment