Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with delete/edit news!
Old 12-04-2005, 04:46 AM Help with delete/edit news!
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
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..
Ickie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-04-2005, 04:36 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
You have not defined '$id'.

Try:

<?php

include "config.inc";

$id = $_GET[id];

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>";

?>
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Reply     « Reply to Help with delete/edit news!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09978 seconds with 12 queries