Код:
<?php
include "../config/db-conn.php";
function bbcode($text){
$text=preg_replace("/\[b\](.+?)\[\/b\]/s", '<b>$1</b>',$text);
$text=preg_replace("/\[i\](.+?)\[\/i\]/s", '<i>$1</i>',$text);
$text=preg_replace("/\[u\](.+?)\[\/u\]/s", '<u>$1</u>',$text);
$text=preg_replace("/\[quote\](.+?)\[\/quote\]/s", '<table cellspacing="1" width="100%" border="0"><tr><td>Quote:</td></tr><tr><td width="100%" style="border:solid 1px black">$1</td></tr></table>',$text);
$text=preg_replace("/\[quote\=(.+?)](.+?)\[\/quote\]/s", '<table cellspacing="1" width="100%" border="0"><tr><td>$1 êàçà:</td></tr><tr><td width="100%" style="border:solid 1px black">$2</td></tr></table>',$text);
$text=preg_replace("/\[url\](.+?)\[\/url\]/s", '<a href="$1">$1</a>',$text);
$text=preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/s", '<a href="$1">$2</a>',$text);
$text=preg_replace("/\[img\](.+?)\[\/img\]/s", '<img src="$1" alt="User submitted image" title="User submitted image"/>',$text);
$text=preg_replace("/\[color\=(.+?)\](.+?)\[\/color\]/s", '<span style="color:$1">$2</span>',$text);
$text=preg_replace("/\[size\=(.+?)\](.+?)\[\/size\]/s", '<span style="font-size:$1">$2</span>',$text);
$text=preg_replace("/\[code\](.+?)\[\/code\]/s",'<table cellspacing="1" width="100%" border="0"><tr><td>Code:</td></tr><tr><td width="100%" style="border:solid 1px black">$1</td></tr></table>',$text);
$text = nl2br($text);
return $text;
}
$cat = $_POST['cats'];
$title = $_POST['title'];
$day = $_POST['day'];
$mount = $_POST['mount'];
$year = $_POST['year'];
$text = $_POST['contents'];
$text = htmlspecialchars($text, ENT_QUOTES);
$text = bbcode($text);
$tag = "oste ne e gotovo";
$query = mysql_query("INSERT INTO `news` ( `id` , `title` , `cont` , `cats` , day`, `mount`, `year`, `tag`)
VALUES ('NULL','$title','$text',$cat,'$day','$mount','$year' , '$tag')");
if ($query) {
echo "Query ok";
echo "<br /><a href=\"../article_list.php\">All articles</a>";
} else {
echo "Query error";
}
?>
а това е формата
Код:
<?php
include "../config/db-conn.php";
?><body>
<title>Add News</title>
<form action="con-news.php" method="post" >
<input type="hidden" value="<?php print(date("j")); ?>" name="day">
<input type="hidden" value="<?php print(date("F")); ?>" name="mount">
<input type="hidden" value="<?php print(date("Y")); ?>" name="year">
<table>
<tr> <td colspan="2"><pre> [i] [u] [quote] [quote="someone"] [url] [url=someurl] [img] [color=fontcolor] [size=fontsize] [code ] </pre></td></tr>
<tr> <td>Category</td><td><select name=cat><?php
$query="SELECT * FROM category ORDER BY name ASC";
$result=mysql_query($query);
while ($i=mysql_fetch_array($result)) {
extract($i); echo "<option name=cats value=\"$name\">$name</option>";
}
?> </select> </td></tr>
<tr><td>Title</td><td><input type="text" name="title"></td></tr>
<tr><td>Text</td><td><textarea name="contents" rows="7" cols="40" class="form_elements_text">content here</textarea></td></tr>
<tr><td colspan="2"><input type="submit" value="Add article"></td></tr>
</table>
</form>
</body>
Структората на Дб-то е:Query error
id | title | cont | cats | day | mount | year | tag