Adding an Article using WYSIWYG text editor with PHP and MYSQL

Language

This is a simple program of adding an Article that uses WYSIWYG text editor with PHP and MYSQL. It is commonly used in Content Management System.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byAnonymous (not verified)on Mon, 01/28/2013 - 14:37

the problem u gt in edit_article.php ,that u defined $newsart_id = $_POST['newsart_id']; ,and there is no need of this post ,u can defined outside the function wher u chk id is numeric or not ,again u did the same mistake wid newcat_id,it was automatically generated, so no need to chk if $newscat_id==' '. remove dis code from edit_article.php ....it will run without error..... :-)

can u explain more details about how to solve the error? u mean remove all the sentences of newcat_id and $newsart_id = $_POST['newsart_id'] ?
Submitted byAnonymous (not verified)on Wed, 10/09/2013 - 17:52

PROBLEM: CAN ANYONE PLEASE HELP ME TO RESOLVE THIS BUG FOR SUBMITTING THE ARTICLE TO EDIT THE DATA. PLEASE!!! THANKS IN ADVANCE PO. ?????!!!
Submitted bySivaraj MCA (not verified)on Thu, 11/07/2013 - 14:50

Submiiting Form is working Fine

Contact : [email protected]

<?php
function renderForm($newsart_id, $newscat_id, $newsart_title, $newsart_details, $month_id, $day_id, $year_id, $newsart_author, $error)
{
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
<title>Edit Article Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<script type="text/javascript" src="../nicEdit.js"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>
<?php include('connect-db.php')?>
<table align="center"><br><br><br><td width="800" align="center"><h1>Edit Article Records</h1><hr></td></table>
<table align="center" ><td width="800" align="center"><a href="article_records.php" class="navlink"><< Back to article records</a><br><br></td></table>
<form method="POST" action="">
<table align="center" class="default-font">
<tr><td valign="top" class="default-font">News ID:</td><td><input type="text" name="newsart_id" value="<?php echo $newsart_id;?>" type="hidden">&nbsp Dont change this ID Number!!!</td></tr>
<tr><td valign="top" class="default-font">News Title:</td><td><input type="text" name="newsart_title" size="50" value="<?php echo $newsart_title;?>"></td></tr>
<tr><td valign="top" class="default-font">Choose News Category:</td><td><label>
<select name="newscat_id" id="input">
<?php
$result = mysql_query("SELECT * FROM newscat_tbl ORDER BY newscat_id ");
$row=$result;
do { ?>
<option value="<?php echo $row['newscat_id'];?>"><?php echo $row['newscat_desc'];?>
<?php } while ($row = mysql_fetch_assoc($result)); ?></option>
</select>
</label></td></tr>
<tr><td valign="top" class="default-font">News Details:</td><td><textarea name="newsart_details" style="width: 500; height: auto;" value="<?php echo $row['newsart_details'];?>"></textarea></td></tr>
<tr><td valign="top" class="default-font">News author:</td><td><input type="text" name="newsart_author" size="50" value="<?php echo $newsart_author;?>"></td></tr>
<tr><td valign="top" class="default-font">Date of Post:</td><td class="font-content-4">
Month:<select name="month_id" id="input">
<?php
$result = mysql_query("SELECT * FROM month_tbl ORDER BY month_id ");
$row=$result;
do { ?>
<option value="<?php echo $row['month_id'];?>"><?php echo $row['month_desc'];?>
<?php } while ($row = mysql_fetch_assoc($result)); ?></option>
</select>

</label>
</label>&nbsp Day: <label>
<select name="day_id" id="input">
<?php
$result = mysql_query("SELECT * FROM day_tbl ORDER BY day_desc ");
$row=$result;
do { ?>
<option value="<?php echo $row['day_id'];?>"><?php echo $row['day_desc'];?>
<?php } while ($row = mysql_fetch_assoc($result)); ?></option>
</select>

</label>&nbsp Year: <label>
<select name="year_id" id="input">
<?php
$result = mysql_query("SELECT * FROM year_tbl ORDER BY year_desc ");
$row=$result;
do { ?>
<option value="<?php echo $row['year_id'];?>"><?php echo $row['year_desc'];?>
<?php } while ($row = mysql_fetch_assoc($result)); ?></option>
</select>

</label>
</td></tr>
</table>
<table align="center">
<tr></td><td width="150" class="font-content-2" valign="top"></td><td><input type="submit" name="submit" onclick="return checkForm();" value="Edit" >&nbsp <input type="reset" value="Reset" ><br><br></td></tr>
</table></form>
<table align="center" style="border: solid 2px red; background-color: pink;"><td width="800" align="center" class="default-font">PROBLEM: CAN ANYONE PLEASE HELP ME TO RESOLVE THIS BUG FOR SUBMITTING THE ARTICLE TO EDIT THE DATA. <br><b>PLEASE!!! THANKS IN ADVANCE PO.</td></table>
<table align="center" ><td width="800" align="center"><a href="index.php" class="navlink">ADD ARTICLE</a>&nbsp|&nbsp <a href="article_records.php" class="navlink">ARTICLE RECORDS</a></td></table>
<table align="center" ><br><br><br><hr ><td align="center" class="default-font">By Bhadzky25 ^_^ Credits to all PHP Programmers and Web Designers for this useful code.</td></table>
</body>
</html>
<?php
}

// connect to the database
include('connect-db.php');

// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['newsart_id']))
{
// get form data, making sure it is valid
$newsart_id = $_POST['newsart_id'];
$newsart_title = mysql_real_escape_string(htmlspecialchars($_POST['newsart_title']));
$newscat_id = $_POST['newscat_id'];
$newsart_details = mysql_real_escape_string(htmlspecialchars($_POST['newsart_details']));
$month_id = mysql_real_escape_string(htmlspecialchars($_POST['month_id']));
$day_id = mysql_real_escape_string(htmlspecialchars($_POST['day_id']));
$year_id = mysql_real_escape_string(htmlspecialchars($_POST['year_id']));
$newsart_author = mysql_real_escape_string(htmlspecialchars($_POST['newsart_author']));

// check that firstname/lastname fields are both filled in
if ($newsart_title == '' || $newscat_id == '' || $newsart_details == '' || $month_id == '' || $day_id == '' || $year_id == '' || $newsart_author == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';

//error, display form
renderForm($newsart_id, $newscat_id, $newsart_title, $newsart_details, $month_id, $day_id, $year_id, $newsart_author, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE news_article SET newsart_title='$newsart_title', newscat_id='$newscat_id', newsart_details='$newsart_details', month_id='$month_id', day_id='$day_id', year_id='$year_id', newsart_author='$newsart_author' WHERE newsart_id='$newsart_id'")
or die(mysql_error());

// once saved, redirect back to the view page
header("Location: edit_success.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error! No ID number selected.';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{

// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['newsart_id']) && is_numeric($_GET['newsart_id']) && $_GET['newsart_id'] > 0)
{
// query db
$newsart_id = $_GET['newsart_id'];
$result = mysql_query("SELECT * FROM news_article WHERE newsart_id=$newsart_id")
or die(mysql_error());
$row = mysql_fetch_array($result);

// check that the 'id' matches up with a row in the databse
if($row)
{

// get data from db
$newsart_title = $row['newsart_title'];
$newsart_details = $row['newsart_details'];
$newscat_id = $row['newscat_id'];
$month_id = $row['month_id'];
$day_id = $row['day_id'];
$year_id = $row['year_id'];
$newsart_author = $row['newsart_author'];
// show form
renderForm($newsart_id, $newscat_id, $newsart_title, $newsart_details, $month_id, $day_id, $year_id, $newsart_author, '');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
}
?>

Submitted bytest one (not verified)on Sat, 11/27/2021 - 00:22

Overview Bootstrap’s form controls expand on our Rebooted form styles with classes. Use these classes to opt into their customized displays for a more consistent rendering across browsers and devices.

Add new comment