Система за новини – Част Седем
продължаваме с админ панела
editnews5.php
<form action="pro.php?page=editnews6" method="post">
<table>
<?php
mysql_connect($server, $dbusername, $dbpassword)or die("Сайтът не може да се свърже към базата данни");
@mysql_select_db($db_name) or die("Грешна база данни");
$id_news = $_GET['id_news'];
$archive="SELECT * FROM news WHERE id_news = '$id_news'";
$godinass=mysql_query($archive);
$num=mysql_numrows($godinass);
mysql_close();
$i=0;
while ($i < $num) {
$id_news=mysql_result($godinass,$i,"id_news");
$title=mysql_result($godinass,$i,"title");
$cats=mysql_result($godinass,$i,"cats");
$newstext=mysql_result($godinass,$i,"newstext");
?>
<tr>
<td>
<input type=hidden name=id_news value=<?php echo "$id_news" ?>>
</td>
</tr>
<tr>
<td>
<b>Заглавие:</b>
</td>
</tr>
<tr>
<td>
<?php echo "$title" ?>
</td>
</tr>
<tr>
<td>
<input type=text name=title size=50>
</td>
</tr>
<tr>
<td>
<b>Категория:</b>
</td>
</tr>
<tr>
<td>
<?php echo "$cats" ?>
</td>
</tr>
<tr>
<td>
<select name=cats>
<?php
mysql_connect($server, $dbusername, $dbpassword)or die("Сайтът не може да се свърже към базата данни");
@mysql_select_db($db_name) or die("Грешна база данни");
$query="SELECT * FROM cat ORDER BY cats ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$cats=mysql_result($result,$i,"cats");
?>
<option name=cats value="<?php echo $cats ?>"><?php echo $cats ?></option>
<?php
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td>
<b>Текст:</b>
</td>
</tr>
<tr>
<td>
<textarea rows="7" name="newstext" cols="60" type="text"><?php echo "$newstext" ?></textarea>
</td>
</tr>
<tr>
<td><input type=submit name=Submit value=Публикуване class=form></td>
</tr>
<?php
$i++;
}
?>
</table>
</form>
editnews6.php
<?php
mysql_query ("UPDATE news SET title='$title', cats='$cats', newstext='$newstext' WHERE id_news='$id_news'");
?>home.php
<H2><B>Добре дошъл админ</B><H2>index.php
<?php session_start();
include('pro1.php');
$username = $_POST['username'];
$password = $_POST['password'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>news admin</title>
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
}
a:link {
color: #FF0000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FF0000;
}
a:hover {
text-decoration: underline;
color: #FF6600;
}
a:active {
text-decoration: none;
color: #FF6600;
}
a {
font-size: 10px;
}
-->
</style></head>
<body>
<table width="400" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999">
<tr>
<td><table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><img src="../img/logo.gif"></div></td>
</tr>
<br>
<center>Административен панел</center>
<br>
<tr>
<td height="145">
<?php if($_POST['submit']){
if($username == $username2 && $password == $password2) {
session_register("username");
$_SESSION['username'] = $username;
echo "<font color=\"#ffffff\"><b>Thank you for login in, you will be redirected to the protected pages in 2 seconds <META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=pro.php\"></b></font>";
}
} ?>
<form name="form1" method="post" action="index.php">
Username:<br>
<input name="username" type="text" id="username">
<br>
Password: <br>
<input name="password" type="password" id="password">
<br>
<br>
<input name="submit" type="submit" id="submit" value="Login!">
<br>
<br>
</form></td>
</tr>
<tr>
<td><div align="center">Powered by <a href="http://webjo.to.md" target="_blank">Web-Journal</a></div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>pro.php
<?php
session_start();
if(!$_SESSION['username']){
echo "Please <a href=index.php>login.</a>";
exit;
}
?>
<?php include ("../config.php"); ?>
<!--
Webjo jooorooo@data.bg
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $CHARSET ?>">
<title><?php echo $TITLEADMIN ?></title>
<script src="../css/bbcode.js">
</script>
</head>
<body>
<center>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="950">
<tr>
<td valign=top width="22%">
<a href=pro.php?page=home>Начало</a><br><a href=pro.php?page=addcat>Добави категория</a><br>
<a href=pro.php?page=addanketa>Нова анкета</a><br><a href=pro.php?page=addnews>Добавяне на новина</a><br>
<a href=pro.php?page=editnews>Редактиране на новина</a><br>
<a href=pro.php?page=editcom>Редактиране на коментар</a>
</td>
<td valign=top width="78%">
<?php
switch ($HTTP_GET_VARS[page]) {
default:
include "home.php";
break;
case 'addanketa':
include 'addanketa.php';
break;
case 'addnews':
include 'addnews.php';
break;
case 'editnews':
include 'editnews.php';
break;
case 'editnews2':
include 'editnews2.php';
break;
case 'editnews3':
include 'editnews3.php';
break;
case 'editnews4':
include 'editnews4.php';
break;
case 'editnews5':
include 'editnews5.php';
break;
case 'editnews6':
include 'editnews6.php';
break;
case 'del':
include 'del.php';
break;
case 'editcom':
include 'editcom.php';
break;
case 'editcom2':
include 'editcom2.php';
break;
case 'editcom3':
include 'editcom3.php';
break;
case 'delcom':
include 'delcom.php';
break;
case 'addcat':
include 'addcat.php';
break;
case 'addnews2':
include 'addnews2.php';
break;
}
?>
</td>
</tr>
</table>
</center>
</body>
</html>pro1.php е последния файл, в който задавате име и парола за администратора.
<?php
$username2 = "admin"; // Your Username
$password2 = "admin"; // Your Password
?>Ако на някои не му е ясно нещо или има въпроси, може да се свържя с мен във форума или на ЛС.


