• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP - little help

Aleh

Active Member
Joined
Jan 9, 2009
Messages
1,228
Reaction score
39
Location
Rzeszów
Hi!
I have little problem.
I have a script:
PHP:
    <span >Choose a character: </span>   
    <form action='?' method='POST'>   
    <select name='postac'> <option value='0'>(Choose character)</option>";  
              
              
        $players_choose = $SQL->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll();  
          
        foreach($players_choose as $player)  
        {  
            $main_content .= '<option value="'.$player['id'].'"';  
            if($player['id'] == $char_id)  
            $main_content .= ' selected="selected"';  
            $main_content .= '>'.$player['name'].'</option>';  
        }  
        </select>
How to do that in a database to save the name you chose and not his ID?
 
You aren't saving anything in that code.

Anyway, I'll take a guess that you want this:
PHP:
   <span >Choose a character: </span>   
    <form action='?' method='POST'>   
    <select name='postac'> <option value='0'>(Choose character)</option>";  
              
              
        $players_choose = $SQL->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll();  
          
        foreach($players_choose as $player)  
        {  
            $main_content .= '<option value="'.$player['name'].'"';  
            if($player['id'] == $char_id)  
            $main_content .= ' selected="selected"';  
            $main_content .= '>'.$player['name'].'</option>';  
        }  
        </select>
 
You aren't saving anything in that code.

Anyway, I'll take a guess that you want this:
PHP:
   <span >Choose a character: </span>   
    <form action='?' method='POST'>   
    <select name='postac'> <option value='0'>(Choose character)</option>";  
              
              
        $players_choose = $SQL->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll();  
          
        foreach($players_choose as $player)  
        {  
            $main_content .= '<option value="'.$player['name'].'"';  
            if($player['id'] == $char_id)  
            $main_content .= ' selected="selected"';  
            $main_content .= '>'.$player['name'].'</option>';  
        }  
        </select>

Thanks for help. It works:)
 
Back
Top