Банер система
Здравейте!

Да започваме:

Първо си правим една таблица: banners


CREATE TABLE IF NOT EXISTS `banners` (
`id` int(10) unsigned NOT NULL auto_increment,
`impresii` int(10) NOT NULL DEFAULT 0,
`klikove` int(10) NOT NULL DEFAULT 0,
`bannercode` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 ;


После:

Създаваш файл banners.php:


<?php
$pass="parolata ti";
$pass2=$_GET["pass"];
if(!isset($pass2) || $pass2 != $pass) die("Mr1sen haker");

function sqlerr($file = '', $line = '')
{
print("<table border=0 bgcolor=blue align=left cellspacing=0 cellpadding=10 style='background: blue'>" .
"<tr><td class=embedded><font color=white><h1>SQL Error</h1>\n" .
"<b>" . mysql_error() . ($file != '' && $line != '' ? "<p>in $file, line $line</p>" : "") . "</b></font></td></tr></table>");
die;
}

if(!$_GET["action"]){
?>
<a href="?action=add&pass=<?=$pass?>">ADD</a>||<a href="?action=edit&pass=<?=$pass?>">EDIT</a>||<a href="?action=del&pass=<?=$pass?>">DELETE</a>
<?
}
?>
<html><head><TITLE>banneredit</TITLE></head><body bgcolor="Maroon">
<?php

if (!@mysql_connect("Hosta ti", "potrebitelq", "parolata"))
{
switch (mysql_errno())
{
case 1040:
case 2002:
default:
die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error());
}
}
mysql_select_db("bazata danni")
or die('dbconn: mysql_select_db: ' + mysql_error());


$action = $_GET["action"];

if($action == "add") {

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$id=$_POST["id"];
$bannercode = $_POST["bannercode"];
mysql_query("INSERT INTO banners (bannercode) VALUES ($bannercode)") or sqlerr(__FILE__, __LINE__);
}
print("<table align=center bgcolor=pink>");
print("<form method=post action=banners.php?action=add&pass=$pass>");
print("<tr><td bgcolor=red width=90%>ADD BANNER</td></tr>");
print("<tr><td>BANNERCODE:<br /><textarea name=bannercode cols=145 rows=5></textarea>");
print("<input type=text class=\"hidden\" value=\"$id\" readonly");
print("<input type=submit value='Okay' class=btn>");
print("</form></table>");
die();
}

elseif($action == "edit") {

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$id=$_POST["id"];
$bannercode = $_POST["bannercode"];

mysql_query("UPDATE banners SET bannercode=$bannercode WHERE id=$id") or sqlerr(__FILE__, __LINE__);
}

$id = 0 + $_GET["id"];

$res = mysql_query("SELECT * FROM banners WHERE id=$id");
$row = mysql_fetch_array($res);
print("<table align=center bgcolor=pink>");
print("<form method=post action=banners.php?action=edit&pass=$pass>");
print("<tr><td bgcolor=red width=90%>EDIT BANNER</td></tr>");
print("<tr><td>BANNERCODE:<br /><textarea name=bannercode cols=145 rows=5>$row[bannercode]</textarea>");
print("<input type=text class=\"hidden\" value=\"$id\" readonly");
print("<input type=submit value='Okay' class=btn>");
print("</form></table>");
die();
}

elseif($action == "del") {
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$id=$_POST["id"];
mysql_query("DELETE FROM banners WHERE id = $id");
}
$id = 0 + $_GET["id"];
$res = mysql_query("SELECT * FROM banners WHERE id=$id");
$row = mysql_fetch_array($res);
print("<table align=center bgcolor=pink>");
print("<form method=post action=banners.php?action=del&pass=$pass>");
print("<input type=text class=\"hidden\" value=\"$id\" readonly");
print("<input type=submit value='Okay' class=btn>");
print("</form></table>");

}
?>
</body></html>



и накрая изкарваш банера така:



<?php
$bannerid = 1; # nomera na banera
$r = mysql_query("SELECT * FROM banners WHERE id=$bannerid");
$r2 = mysql_fetch_array($r);
print($r2["bannercode"]);
?>


Надявам се да съм бил полезен.

Системата не е изпробвана и не съм сигурен дали работи. Ако не, пишете долу в коментарите.






/ Трябва да сте регистриран за да напишете коментар /
От: Styl3r
16:55 19-03-2010
да прав си не работи :(
От: gamena007
9:31 20-03-2010
Този урок е писан преди 2 години. Има много пропоски в него. Скоро ще го напиша на ново.
От: thuglife
16:47 21-11-2010
gamena007 ako iskash da stanesh ot ekip programisti za napravata na websaitove sreshty raplata pi6i na thugwe@abv.bg
1