<?php
require('../config.php');
require('../NewsScript.php');
/**
* Here we have clicked the button to update our edited article
* We need to update it in the database
*/
if(isset($_POST['Submit']))
{
$news = new NewsScript();
if($news->updateNews($_GET['id'], $_POST['txtAuthor'], $_POST['txtContent']))
{
echo "Update complete!";
}
else echo "Update Error!";
exit();
}
else // page loads but form not submitted
{
if(is_numeric($_GET['id']))
{
$connection = mysql_connect($db_host, $db_user, $db_password)
or die("Unable to connect to MySQL");
mysql_select_db($db_name, $connection) or die("Unable to select DB!");
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM newstbl WHERE id = '$id'");
$row = mysql_fetch_assoc($result);
$author = $row['author'];
$content = $row['content'];
mysql_close($connection);
}
else echo "None numeric Value!";
}
/**
* output our content
*
*/
function showContent()
{
global $content;
echo $content;
}
/**
* output the author
*
*/
function showAuthor()
{
global $author;
echo 'value="'. $author . '"';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit News</title>
</head>
<body>
<h1>Edit News</h1>
<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Name</td>
<td><input type="text" name="txtAuthor" <? showAuthor();?> /></td>
</tr>
<tr>
<td>News</td>
<td><textarea name="txtContent" cols="60" rows="5"><? showContent();?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Update" /></td>
</tr>
</table>
</form>
</body>
</html>
|