Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Jun 2002
Posts: 62
Junior Member
OP Offline
Junior Member
Joined: Jun 2002
Posts: 62
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.

this is the delete form
Code
 
<form action="delete_notice.php" method="post">
$query = "SELECT title, id FROM notices";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){

?> <input name="<? echo "$row[id]"; ?>" type=checkbox>  <? echo "$row[title]";
print '
';
}
?>


<input type="submit" value="Delete selected">
</form>
 
and this is the query that deletes the entries
Code
 
$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."
Joined: Mar 2002
Posts: 1,136
P
UGN Elite Poster
Offline
UGN Elite Poster
P
Joined: Mar 2002
Posts: 1,136
You also need a value in your checkbox tags, I think.

Joined: Jun 2002
Posts: 62
Junior Member
OP Offline
Junior Member
Joined: Jun 2002
Posts: 62
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."
Joined: Mar 2002
Posts: 197
P
Member
Offline
Member
P
Joined: Mar 2002
Posts: 197
You need to check if the selectboxes are checked or not. The name of the checkbox will be passed on as a post variable.


Never argue with fools... They will only drag you down to their level, and beat you with experience...
Joined: Mar 2002
Posts: 256
Likes: 1
UGN Security Staff
Offline
UGN Security Staff
Joined: Mar 2002
Posts: 256
Likes: 1
?> <input name="<? echo "$row[id]"; ?>" type=checkbox> <? echo "$row[title]";


$query = "DELETE FROM notices WHERE 'id' = '$id' ";


those are 2 lines w. errors as I scanned through...
Code
?> <input name="<? echo $row["id"]; ?>" type=checkbox>  <? echo $row["title"];
and the more important one

Code
$query = "DELETE FROM notices WHERE `id`=$id";

Joined: Mar 2002
Posts: 1,136
P
UGN Elite Poster
Offline
UGN Elite Poster
P
Joined: Mar 2002
Posts: 1,136
actually, I think it's

Code
$query = "DELETE FROM notices WHERE id='$id';
no quotes around id (the column)

Joined: Mar 2002
Posts: 256
Likes: 1
UGN Security Staff
Offline
UGN Security Staff
Joined: Mar 2002
Posts: 256
Likes: 1
no bish, there feet! not single quotes! thats uber important! heh

Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
This should put you closer.

Code
<form action="delete_notice.php" method="post">
	<?
	$query = mysql_query("SELECT title, id FROM notices");
	$numrows = mysql_num_rows($query);
	while($query2 = mysql_fetch_array($query))
	{
		?> 
		<input name="data" id="data" value="<? echo ".$query2[id]."; ?>" type=checkbox>  
		<? 
		echo ".$query2[title].";
		print '
';
	}
?>


<input type="submit" value="Delete selected">
</form> 
Code
<?
$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.

Joined: Jun 2002
Posts: 62
Junior Member
OP Offline
Junior Member
Joined: Jun 2002
Posts: 62
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."
Joined: Mar 2002
Posts: 256
Likes: 1
UGN Security Staff
Offline
UGN Security Staff
Joined: Mar 2002
Posts: 256
Likes: 1
erm this might work Its actually supposed to be a combonation.
Code
$query = "DELETE FROM notices WHERE `id`='$id'";
hey, do this also.
Code
mysql_query($query) or die(mysql_error());
just to give us an Idea...

Joined: Oct 2003
Posts: 1
Junior Member
Offline
Junior Member
Joined: Oct 2003
Posts: 1
Please help me to do a chat or post in javascript

Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Paulo Breda

A chat would probably be best writen in Java. You can learn how to make an applet. look for pergesu on here he knows Java.

http://java.sun.com

For a post... I assume you mean a bulleting board. You might want to try

Perl
PHP/MySQL
Python
Delphi
JSP
ASP

any of those will allow you to code a web board.

If you start today you might know enough in about 1 year to code a full bulletin board like this one.


Link Copied to Clipboard
Member Spotlight
Posts: 43
Joined: November 2002
Forum Statistics
Forums41
Topics33,840
Posts68,858
Average Daily Posts1
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Where and how do you torrent?
by danni75 - 03/01/24 05:58 AM
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
unreal 1
Crime 1
Ice 1
Dartur 1
Powered by UBB.threads™ PHP Forum Software 7.7.5