mysql - PHP - Upload data to database using a loop -
i have array contains $player_ids. array obtained in form user used select team. query database $player_ids array. such:
if ( isset($_post['submit']) ) { $player_ids = array_map('intval', $_request['players']); var_dump($player_ids); $query = 'select `name` `player_info` `player_id` in (' . implode(',', $player_ids) . ')'; $return_names = mysql_query($query) or die(mysql_error()); while ( $row = mysql_fetch_assoc($return_names) ) { $selected[] = $row['name']; } var_dump($selected);
the above code working , when open in browser output
now want extract values array $selected (which contains names of players selected) , upload database. try follows:
foreach ($selected $player){ $sql = mysql_query('insert `team`(`player_name`) values ("$player")') or die(mysql_error()); print ($player); echo'<br>'; ` }
im suspecting above code problem comes in. when above code executed database contains array name , not actual values of array. following picture shows:
if point me in right direction, why array name , not values gets saved in database appreciated.
thanks in advance.
you must put double quotes around string instead of single quotes. in single quoted strings variables $player not replaced value interpreted there text.
Comments
Post a Comment