I have scripts I made for adding news, links, etc to a website using php & mysql that used to work. Now when I try to use them it just refreshes the form you use to add the news.
I haven't made any changes to the scripts and I don't think anyone else has either so I'm thinking it might have to do with PHP updating their code again, because the last time they updated I had to rewrite all the scripts for uploading .. now it seems I may have to rewrite even more since they don't have backwards compatability... anyways take a look at this code and let me know if it can be easily solved without starting all over.
<?
session_start();
header("Cache-control: private"); // Fix IE6 problem with saving info and back button
if(isset($_SESSION['adminname']))
{
//do nothing
}
else
{
header("Location: ./admin_login.php?err=2");
exit;
}
require 'include.php'; //This is the file you edit for your database.
// If the user wants to add news
if (isset($addnews)):
?>
<html>
<head>
<style type="text/css">@import "styles.css";
</style>
<link rel="stylesheet" href="<? echo STYLESHEET; ?>">
</head>
<body bgcolor="#333333">
<p> </p>
<table bgcolor=#333333 text="#FFFFFF" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00" valign=top align=center border=1 width="300">
<tr>
<td>
<form method="post" action="<? echo "$PHP_SELF"; ?>">
<table cellpadding=0 bgcolor=#ffffff cellspacing=0 border=0 width="280" align="center">
<tr bgcolor="#333333">
<th colspan="2" class="links_descriptions">Add :: News</th>
</tr>
<tr bgcolor="#333333">
<td colspan="2">
<div align="right"></div>
<div align="right">
<textarea name="addNEWS" cols="35" rows="10"></textarea>
</div>
</tr>
<tr bgcolor="#333333">
<td>
<td>
<div align="right">
<input type=submit value="Add News" name="add_news">
</div>
</tr>
</table>
</form>
</td>
</table>
<p> </p>
</body>
</html>
<?php
else:
//--- connect to database
// $connection = mysql_connect($DBhost, $DBuser, $DBpass) or die ("Unable to connect to MySQL server.");
// $db = mysql_select_db($DBname, $connection) or die ("Unable to select database.");
//------ If user adds news -------
if ($add_news){
$addNewsID = uniqid("addNewsID"); // Increment the ID
//----- Get the current Time - EST
$timestamp = time();
$hoursdiff = 0; //change this to how many hours minus UTC time you want to set the clock to
$hoursdiff = $hoursdiff * 3600;
$timestamp = $timestamp - $hoursdiff;
$date1 = date("F d, Y", $timestamp);
$time1 = date("h:iA", $timestamp);
//print "$time1, $date1";
$thetime = "$time1|$date1";
//-------- End Get the current Time - EST
// Connect to database
$connection = mysql_connect($DBhost, $DBuser, $DBpass)or die ("Unable to connect to MySQL server.");
$db = mysql_select_db($DBname, $connection) or die ("Unable to select database.");
$sql = "INSERT INTO $tnw_news (id,news,tnw_time)
VALUES ('$addNewsID','$addNEWS', '$thetime')";
$sql_result = mysql_query($sql,$connection);
//----- If there was no result - print out error message
if(!$sql_result)
{
mysql_close($connection);
?>
<center><span class="white">News: <br><? echo "<b>$addNEWS</b>" ?> <br>not added. ID already used. Thank you.</span></center>
<?
echo mysql_error();
}
//----- If there was a result - print out sucessfull message
if($sql_result)
{
mysql_close($connection);
?>
<center><span class="white">News: <br><? echo "<b>$addNEWS</b>" ?> <br>added sucessfully!</span></center>
<?
}
else
{
//do nothing
}
}
//-------- END ADD NEWS ---------------------------//
//-------- DELETE NEWS ---------------------------//
// If news has been deleted,
// remove it from the database.
if (isset($delete_news)) {
// Connect to database
$connection = mysql_connect($DBhost, $DBuser, $DBpass)or die ("Unable to connect to MySQL server.");
$db = mysql_select_db($DBname, $connection) or die ("Unable to select database.");
$sql = "DELETE FROM $tnw_news
WHERE id=$delete_news";
if (@mysql_query($sql)) {
?>
<html>
<head>
<style type="text/css">
</style>
<link rel="stylesheet" href="<? echo STYLESHEET; ?>">
</head>
<body bgcolor="#666666" text="#FFFFFF" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00" >
<?
echo("<center><p>The news item has been deleted.</p></center>");
} else {
echo("<center><p>Error deleting news: " .
mysql_error() . "</p></center>");
}
}
// When clicked, this link will load this page
// with the news submission form displayed.
echo("<center><p><a href='$PHP_SELF?addnews=1'>Click to add a news item</a></p></center>");
echo("<center><p> Here is the news listed in the database: </p></center>");
// Request the ID and text of all news
$connection = mysql_connect($DBhost, $DBuser, $DBpass) or die ("Unable to connect to MySQL server.");
$db = mysql_select_db($DBname, $connection) or die ("Unable to select database.");
$result = @mysql_query("SELECT id, news, tnw_time FROM $tnw_news");
if (!$result) {
echo("<center><p>Error performing query: " . mysql_error() . "</p></center>");
exit();
}
// Display the text of each news item in a paragraph
// with a "Delete" link next to each.
while ( $row = mysql_fetch_array($result) ) {
$newsid = $row["id"];
$news = $row["news"];
$tnw_time = $row["tnw_time"];
?>
<html>
<head>
<style type="text/css">
</style>
<link rel="stylesheet" href="<? echo STYLESHEET; ?>">
</head>
<body bgcolor="#666666" text="#FFFFFF" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00" >
<table border="0" cellspacing="6" cellpadding="6" bgcolor="#666666">
<tr align="left" valign="top" bgcolor="#666666">
<td >
<p><img src="images/news_icon.gif" width="24" height="12"><span class="white"><? echo "$tnw_time" ?><br></span>
<img src="images/news_divider.gif" width="552" height="1"><br>
</p>
<p> <span class="white"><? echo("<p>$news " . "</br><a href='$PHP_SELF?delete_news=$newsid'>" . "Delete</a></p>"); ?></span>
</td>
</tr>
</table>
<?
}
// When clicked, this link will load this page
// with the news submission form displayed.
echo("<center><p><a href='$PHP_SELF?addnews=1'>Click to add a news item</a></p></center>");
endif;
?>
</body>
</html>