Просмотр поста

.
Fenix_61

<?php
define('_IN_JOHNCMS', 1);
$rootpath = '';
require_once ('incfiles/core.php');
require_once ('incfiles/head.php');
switch ($act){
default:
$res = mysql_query("SELECT * FROM `stat`");
while ($cat = mysql_fetch_array($res)){
echo $cat['name'].' <a href="index.php?act=edit&amp;id='.$cat['id'].'">[e]</a> <a href="index.php?act=del&amp;id='.$cat['id'].'">[x]</a>';}
break;
case 'edit':
$id = intval($_GET['id']);
if (isset($_POST['submit'])){
$up = mysql_query("UPDATE `stat` SET `name` = '" . trim(mysql_real_escape_string($_POST['name'])) . "' where `id` = '".$id."'");
if ($up) header('location:index.php'); else echo mysql_error();
}else{
echo '<form method="post" action="index.php?act=edit&amp;id='.$id.'"><input type="text" name="name"/><input type="submit" name="submit" value="Изменить"/></form>';
}
break;
case 'del':
$id = intval($_GET['id']);
if (isset($_POST['submit'])){
$up = mysql_query("DELETE FROM `stat` where `id` = '".$id."'");
if ($up) header('location:index.php'); else echo mysql_error();
}else{
echo '<form method="post" action="index.php?act=del&amp;id='.$id.'"><input type="submit" name="submit" value="Удалить"/></form>';
}
break;
}
require_once ('incfiles/end.php');