SOLVED, made a better script .
delete_news.php
PHP Code:
<?php
include "config.inc";
mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die ("Could not select database.");
mysql_query("DELETE * FROM news WHERE id='$id'");
echo "Thank you! News deleted successfully! Redirecting..."; echo "<meta http-equiv=Refresh content=1;url=index.php>";
?>
edit_news.php
PHP Code:
<?php
include "config.inc";
mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die ("Could not select database.");
if(isset($_POST['submit'])) { $title = ($_POST['title']); $text = ($_POST['text']);
$result = mysql_query("UPDATE news SET title='$title', text='$text' WHERE id='$id'");
echo "Thank you! News updated successfully! Redirecting..."; echo "<meta http-equiv=Refresh content=1;url=index.php>";
} elseif($id) {
$result = mysql_query("SELECT * FROM news WHERE id='$id'");
while($row = mysql_fetch_assoc($result)) { $title = $row["title"]; $text = $row["text"];
?>
<h1>Edit News</h1> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="id" value="<? echo $row['id']?>"> Title: <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"><br /> Text: <textarea name="text" rows="7" cols="30"><? echo $text; ?></textarea><br /> <input type="submit" name="submit" value="Update News"> </form>
<? } } ?>
I don't get any error when running them, they just don't do what their meant to...
Oh and if it's any help heres my add_news.php
PHP Code:
<?php
include "config.inc";
mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die ("Could not select database.");
if(isset($_POST['submit'])) { $title = ($_POST['title']); $text = ($_POST['text']);
if(!$title) { echo "Error: News title is a required field. Please fill it."; exit(); }
$result = mysql_query("INSERT INTO news (date, title, text) VALUES (NOW(),'$title','$text')");
echo "Thank you! News added successfully! Redirecting..."; echo "<meta http-equiv=Refresh content=1;url=index.php>";
} else {
?>
<h1>Add News</h1> <form method="post" action="<?php echo $PHP_SELF ?>"> Title: <input name="title" size="40" maxlength="255"><br /> Text:<textarea name="text" rows="7" cols="30"></textarea><br /> <input type="submit" name="submit" value="Add News"> </form>
<? } ?>
Last edited by Ickie; 12-04-2005 at 07:58 AM..
|