Webboard

Pełna wersja: Pomoc przy kodzie, dodanie pola "Hasło"
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Witam, mam problem ponieważ chcę zrobić że hasło do postaci będzie inne niż jest do konta globalnego, w szablonie games_samp_newchar dodałem {$lang->games_samp_char_pass} i teraz trzeba do pliku games.php dodać te pole żeby po wpisaniu w okno "Hasło" wysyłało do tabeli mybb_games_konta, pole "Key"

Kod PHP:
<form action="games.php?game=samp&action=newchar" method="post">
<
tr><td class="thead" colspan="2"><strong>{$lang->games_samp_newchar}</strong>{$games_nav}</td></tr>
<
noscript><tr><td class="tcat" colspan="2"><div class="error"><p><em>{$lang->games_samp_newcharacter_js_warning}</em></p></div></td></tr></noscript>
{
$errors}
<
tr><td class="trow2"><strong>{$lang->games_samp_char_name}</strong></td><td class="trow2"><input maxlength="21" type="text" name="name" value="{$mybb->input['name']}/></td></tr>
<
tr><td class="trow1"><strong>{$lang->games_samp_char_surname}</strong></td><td class="trow1"><input maxlength="21" type="text" name="surname" value="{$mybb->input['surname']}/></td></tr>
<
tr><td class="trow1"><strong>{$lang->games_samp_char_pass}</strong></td><td class="trow1"><input maxlength="21" type="text" name="surname" value="{$mybb->input['pass']}/></td></tr>
<
tr><td class="trow2"><strong>{$lang->games_samp_char_age}</strong></td><td class="trow2"><input type="text" maxlength="2" name="age" value="{$mybb->input['age']}/></td></tr>
<
tr><td class="trow1"><strong>{$lang->games_samp_char_sex}</strong></td><td class="trow1"><select name="sex" id="ssel"><option{$selected['male']} value="1">{$lang->games_samp_char_sexmale}</option><option{$selected['female']} value="2">{$lang->games_samp_char_sexfemale}</option></select></td></tr>
<
tr><td class="tcat" colspan="2"><strong>{$lang->games_samp_char_skin}</strong></td></tr>
<
tr><td class="trow1" colspan="2" style="text-align: center;"><div id="ssel1"{$maledisplay}>{$maleskins}</div><div id="ssel2"{$femaledisplay}>{$femaleskins}</div></td></tr>
<
script type="text/javascript">
    
jQuery(".skin").click( function () {
        if( 
jQuery("#skin").val() != jQuery(this).attr("id").substr(1))
        {
            
jQuery(".skin").fadeTo("fast"0.33);
            
jQuery(this).fadeTo("fast"1);
            
jQuery("#skin").valjQuery(this).attr("id").substr(1) );
        }
        else
        {
            
jQuery(".skin").fadeTo("slow"1);
            
jQuery("#skin").val("");
        }
    });
    
jQuery("#ssel").change( function () 
    { 
        if(
jQuery(this).val() == '1'
        {
        
jQuery("#ssel1").slideDown("slow"); 
        
jQuery("#ssel2").slideUp("slow");
        }else if(
jQuery(this).val() == '2'
        { 
        
jQuery("#ssel2").slideDown("slow"); 
        
jQuery("#ssel1").slideUp("slow");
        }else{ 
        
jQuery("#ssel1").slideUp("slow"); 
        
jQuery("#ssel2").slideUp("slow"); 
        }
    });
</
script>
<
input type="hidden" name="skin" id="skin" value="" />
<
tr><td class="tfoot" colspan="2"><input type="submit" name="submitchar" value="{$lang->games_samp_newchar_submit}/></td></tr>
</
form
Kod PHP:
//Newchar
    
if($mybb->input['action']=="newchar")
    {
        if(
$mybb->usergroup['gid']==|| $mybb->user['uid']<|| $mybb->user['game_activation']<1)
        {
            
error_no_permission();
        }
        
$query=$db->simple_select("game_konta","*","`CK`='0' AND `Godziny`<5 AND `uid`='".$mybb->user['uid']."'");
        if(
$db->num_rows($query)>0)
        {
            
error($lang->games_samp_newchar_5_hours);
        }
        if(isset(
$mybb->input['submitchar']))
        {
            
$e=0;
            if(empty(
$mybb->input['name']) || empty($mybb->input['surname']) || empty($mybb->input['skin']) || empty($mybb->input['age']) || empty($mybb->input['sex']))
            {
                
$warnings.="<li>".$lang->games_samp_newchar_empty_inputs."</li>";
                
$e++;
            }
            if(!empty(
$mybb->input['name']) && !empty($mybb->input['surname']))
            {
                if((
strlen($mybb->input['name'])+strlen($mybb->input['surname']))>23)
                {
                    
$warnings.="<li>".$lang->games_samp_newchar_name_surname_too_long."</li>";
                    
$e++;
                }
                
$query=$db->simple_select("game_konta","*","`name`='".$db->escape_string($mybb->input['name'])."_".$db->escape_string($mybb->input['surname'])."'",array("limit"=>1));
                if(
$db->num_rows($query)>0)
                {
                    
$warnings.="<li>".$lang->games_samp_newchar_char_exists."</li>";
                    
$e++;
                }
            }
            if(!empty(
$mybb->input['name']))
            {
                if(
strlen($mybb->input['name'])<2)
                {
                    
$warnings.="<li>".$lang->games_samp_newchar_name_enough_long."</li>";
                    
$e++;
                }
            }
            if(!empty(
$mybb->input['surname']))
            {
                if(
strlen($mybb->input['surname'])<2)
                {
                    
$warnings.="<li>".$lang->games_samp_newchar_surname_enough_long."</li>";
                    
$e++;
                }
            }
            if(!empty(
$mybb->input['age']))
            {
                if(
$mybb->input['age']<15 || $mybb->input['age']>80)
                {
                     
$warnings.="<li>".$lang->games_samp_newchar_age_old_young."</li>";
                    
$e++;
                }
            }
            if(
$mybb->input['sex']<&& $mybb->input['sex']>2)
            {
                
$warnings.="<li>".$lang->games_samp_newchar_bad_sex."</li>";
                
$e++;
            }
            if(!empty(
$mybb->input['skin']))
            {
                
$query=$db->simple_select("game_skins","*","`sex`='".$db->escape_string($mybb->input['sex'])."' AND `id`='".$db->escape_string($mybb->input['skin'])."'",array("limit"=>1));
                if(
$db->num_rows($query)<1)
                {
                    
$warnings.="<li>".$lang->games_samp_newchar_bad_skin."</li>";
                    
$e++;
                }
            }
            if(
$e==0)
            {
                
$array=array(
                    
"name"=>$db->escape_string($mybb->input['name'])."_".$db->escape_string($mybb->input['surname']),
                    
"Char"=>$db->escape_string($mybb->input['skin']),
                    
"Wiek"=>$db->escape_string($mybb->input['age']),
                    
"Plec"=>$db->escape_string($mybb->input['sex']),
                    
"Rejestracja"=>date("Y-m-d H:i:s"),
                    
"OstatnieLogowanie"=>"0000-00-00 00:00:00"
                    
"uid"=>$mybb->user['uid']
                );
                
$db->insert_query("game_konta",$array);
                
header("Location: ".str_replace("&amp;","&",get_profile_link($mybb->user['uid'])));
            }
            else
            {
                
$errors inline_error($warnings);
            }
        }
        
$none=" style=\"display: none;\"";
        if(
$mybb->input['sex'])
        {
            if(
$mybb->input['sex']==1)
            {
                
$femaledisplay=$none;
                
$maledisplay=null;
                
$selected['male']=" selected";
            }
            else
            {
                
$femaledisplay=null;
                
$maledisplay=$none;
                
$selected['female']=" selected";
            }
        }
        else
        {
            
$femaledisplay=$none;
            
$maledisplay=null;
        }
        
$query=$db->simple_select("game_skins","*");
        while(
$row=$db->fetch_array($query))
        {
            if(
$row['sex']==1)
            {
                eval(
"\$maleskins .= \"".$templates->get("games_samp_newchar_skin")."\";");
            }
            else
            {
                eval(
"\$femaleskins .= \"".$templates->get("games_samp_newchar_skin")."\";");
            }
        }
        eval(
"\$content = \"".$templates->get("games_samp_newchar")."\";");
        
$title.=" &raquo; ".$lang->games_samp_newchar;
    } 
Tu masz hasło jak widzę:
Kod:
<input maxlength="21" type="text" name="surname" value="{$mybb->input['pass']}" />
to name nie surname, bo to już wysyłasz tylko chociażby key, pass co tam chcesz. type="text" też średnio - daj type="password"

W tym drugim masz walidacje pól, z hasłem też powinno się coś pokombinować - żeby nie jednoznakowe itd.
i zależnie od tego jak się nazywa pole w bazie game_konta dodajesz do tablicy $array jeszcze jeden element
"kolumna"=>$db->escape_string($mybb->input['pass']),