Файл: public_html/tmp/inc/mode.edit.php
Строк: 35
<?php
#by FeST
#ICQ : 3452223
#Действия с таблицами
$table=chek($_GET['table']);
$col=abs(intval($_GET['col']));
        $col_end=$col!=0 ? $col : $col+1; 
    #Обзор базы
    $query="SHOW FULL FIELDS FROM ".$table."";
        $arr = mysql_query($query); 
        
        if(!$arr) echo "Произошла ошибка: ".mysql_error(); 
            if(mysql_num_rows($arr)) 
            { 
             $for_count=mysql_num_rows($arr);
             if(isset($_POST['del']) || isset($_GET['del']))
             echo "<div class='msg'>Вы действительно хотите удалить данную запись?<br/>
             <a href='index.php?table=".$table."&mode=edit&col=".$col."&delete'>Да</a>|<a href='index.php?table=".$table."&mode=edit&col=".$col."'>Нет</a></div>";
                echo "
                <form method='post' action='index.php?table=".$table."&mode=edit&col=".$col."'>
                <table border='1' width='100%'><tr align='center'>";
                    $array=array();
                    
                    while($q=mysql_fetch_array($arr)){
                    echo "<td><b>".$q[0]."</b></td>";
                    if($q[4]=='PRI')$primary=$q[0];
                    $array[]=$q[0];
                    }
                    echo "</tr>";
                    
                    
                    
                    $quert=mysql_query("SELECT * FROM `".$table."` LIMIT ".($col).",".($col_end)."");    
                        
                        $arr=mysql_fetch_array($quert);
                        echo "<tr align='center'>";
                            for($i=0;$i<$for_count;$i++){
                            if($array[$i]==$primary)$primary_value=chek($arr[$i]);
                            echo "<td><input size='5' name='".$array[$i]."' value='".chek($arr[$i])."' /></td>";
                        }
                        echo "</tr>";
                        
                                
                            
                            
                            
                echo "<input type='submit' name='submit' value='Изменить' /><br/><input type='submit' name='del' value='Удалить' /></table></form>
                <hr/>
                <b style='color:red;'>ВНИМАНИЕ!</b><br/> Не редактируйте то, чего не понимаете!<hr/>
                « <a href='index.php?table=".$table."&mode=browse'>Обзор таблицы "".$table.""</a>";
                
                if(isset($_POST['submit'])){
                        $kv = array();
                        foreach ($_POST as $key => $value) {
                        if($key=='submit' || empty($value))
                        continue;
                        else
                        $kv[] = str_ireplace($key,'`'.$key.'`',$key)."=".str_ireplace($value,"'$value'",$value);
                        
                            }
                        //$sql="UPDATE `".$table."` SET ".implode(', ',$kv)." WHERE `".$primary."`='".$primary_value."' LIMIT 1";
                        $up=mysql_query("UPDATE `".$table."` SET ".implode(',',$kv)." WHERE `".$primary."`='".$primary_value."' LIMIT 1");
            if($up)header("Location:index.php?table=".$table."&mode=edit&col=".$col."&sql_ok");
            else    header("Location:index.php?table=".$table."&mode=edit&col=".$col."&sql_no");
            }
            
            if(isset($_GET['delete'])){
            
            $up=mysql_query("DELETE FROM `".$table."` WHERE `".$primary."`='".$primary_value."' LIMIT 1");
            if($up)header("Location:index.php?table=".$table."&mode=browse&sql_ok");
            else    header("Location:index.php?table=".$table."&mode=browse&sql_no");
            
            }
            }
?>