rendered paste body <?php
require('configs/mysql_connect.php');
function nl2br_skip_html($string)
{
// remove any carriage returns (mysql)
$string = str_replace("\r", '', $string);
// replace any newlines that aren't preceded by a > with a <br />
$string = preg_replace('/(?<!>)\n/', "<br />\n", $string);
return $string;
}
$query = "select * from news order by n_date desc";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<td class=ntitle>';
echo stripslashes($row['n_title']);
echo '</td><td class=ndate>';
echo stripslashes($row['n_date']);
echo '</td><td class=ncontent>';
echo stripslashes($row['n_story']);
echo '</td><td class=nedit><a href=?a=edit&r='.stripslashes($row['id']).'>edit</a> | <a href=?a=delete&r='.stripslashes($row['id']).'>delete</a></td>';
}
$action = $_GET['a'];
switch ($action) {
case '':
case 'default':
echo '<table>';
echo '<tr>';
echo '<form name="story" method="post" action="nadmin.php?a=add">';
echo 'Add a new story:<br><br>';
echo '<td>Title of story:</td><td><input type="text" name="storyTitle"></td>';
echo '</tr><tr>';
echo '<td>Current date:</td><td><input type="text" name="storyDate"></td>';
echo '</tr><tr>';
echo '<td>Content:<br>';
echo '</td>';
echo '<table>';
echo '<tr>';
echo '<td>';
echo '<input type="button" onClick="document.story.storyContent.value+=\'<a href=http://www.linkhere.com>Link text</a>\'" value="URL" name="url" title="Add link">';
echo '<input type="button" onClick="document.story.storyContent.value+=\'<b>bold text here</b>\'" value="B" name="bold" title="bold">';
echo '<input type="button" onClick="document.story.storyContent.value+=\'<i>italic text here</i>\'" value="I" name="italic" title="italic">';
echo '</td>';
echo '</tr>';
echo '<table>';
echo '<tr>';
echo '<td><textarea cols="70" rows="25" name="storyContent" onFocus="document.story.storyContent.value=\'\'">Story here</textarea></td>';
echo '</tr><td><input type="button" value="Display" onclick="display();"><input type="submit" value="Submit"></td>';
echo '</form>';
echo '</tr></table>';
break;
case 'add':
$storyTitle = $_POST['storyTitle'];
$storyDate = $_POST['storyDate'];
$storyContent = $_POST['storyContent'];
$parsedContent = nl2br_skip_html($storyContent);
echo $parsedContent;
break;
}
?>