Sponsor Advertisements help keep UGN Security Online.
Sponsor Advertisements help keep UGN Security Online.
Want to earn prizes for clicking online advertisements? Join Rewards1.com.
Latest Postings
Latest Reviews
Topic Options
Rate This Topic
#19317 - 07/06/0309:00 PMhelp with a php/mysql news script
UndeadBob
Junior Member
Registered: 06/11/02
Posts: 62
Loc: UK
i'm writing my own news script using php and mysql. but i have hit a problem. when i try to delete one entry they all get deleted. i know where the problem is but i don't know how to fix it. what happens is when you want to delete a entry you tick a checkbox next to the entry you want to get rid of and it should be deleted. but the php/mysql is setup so that the checkbox on the form are named after the mysql database id. that id number isn't sent to mysql when the delete request is made so all the entrys are deleted. the relevant code is attached. any help is appreciated.
$id = $_POST['id'];
$link = mysql_connect("localhost", $dbuser, $dbpass) or die ("Database Error: Couldn't Connect!");
mysql_select_db($dbname, $link) or die ("Couldn't open $dbname!");
$query = "DELETE FROM notices WHERE 'id' = '$id' ";
mysql_query($query, $link) or die ("Couldn't delete data!");
mysql_close($link);
include "header.php";
print '<center>';
print '
';
print 'Notice(s) succesfully deleted';
print '
';
print '<a href="noticeadmin.php">Return to Notices Administration</a>';
print '<center>';
the table that is being accesed is notice and the fields are id (auto-incrementing id no.), title and notice. i missed out the mysql connect stuff becuase that is ok.
many thanx
_________________________
"Mrs. Jones, I'm sorry to inform you, but we've run the tests, and it appears that you have XP. Now don't cry - it's bad, but it's not a death sentence. Modern science has advanced in recent years, and it's now possible to live a reasonably happy life with XP. And there's a survivor's group that you'll want to meet as well."
#19319 - 07/07/0312:13 PMRe: help with a php/mysql news script
UndeadBob
Junior Member
Registered: 06/11/02
Posts: 62
Loc: UK
i tried giving them a value but it made no difference. any more help will be greatly appreciated
_________________________
"Mrs. Jones, I'm sorry to inform you, but we've run the tests, and it appears that you have XP. Now don't cry - it's bad, but it's not a death sentence. Modern science has advanced in recent years, and it's now possible to live a reasonably happy life with XP. And there's a survivor's group that you'll want to meet as well."
<?
$id = $_POST['id'];
$link = mysql_connect("localhost", $dbuser, $dbpass) or die ("Database Error: Couldn't Connect!");
mysql_select_db($dbname, $link) or die ("Couldn't open $dbname!");
$query = "DELETE FROM notices WHERE 'id' = '$data'";
mysql_query($query, $link) or die ("Couldn't delete data!");
mysql_close($link);include "header.php";print '<center>';
print '
';
print 'Notice(s) succesfully deleted';
print '
';
print '<a href="noticeadmin.php">Return to Notices Administration</a>';
print '<center>';
?>
Code:
$query = "DELETE FROM notices WHERE 'id' = '$data'";
This is the only line I changed. You need to put that in a while loop and process the array that will now be created.
data[0] data[1] data[2] etc etc etc...
might even want to try this
Code:
$dbuser = "username";
$dbpass = "password";
$link = mysql_connect("localhost", $dbuser, $dbpass) or die ("Database Error: Couldn't Connect!");
mysql_select_db($dbname, $link) or die ("Couldn't open $dbname!");
$query = mysql_query("DELETE FROM notices WHERE 'id' = '$data' LIMIT 1");
It can work. I did it for my messenger. If you realy want me to show you let me know. Check my forms. Get an account at http://www.tradebikes.com and message me. View the source and look at my checkbox HTML and compare to yours. I think I needed a for loop.
#19325 - 07/14/0306:01 PMRe: help with a php/mysql news script
UndeadBob
Junior Member
Registered: 06/11/02
Posts: 62
Loc: UK
i am still having problems, the above suggestions didn't really help. more help will be greatly accepted.
_________________________
"Mrs. Jones, I'm sorry to inform you, but we've run the tests, and it appears that you have XP. Now don't cry - it's bad, but it's not a death sentence. Modern science has advanced in recent years, and it's now possible to live a reasonably happy life with XP. And there's a survivor's group that you'll want to meet as well."