UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
December
Su M Tu W Th F Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Our Sponsors


Latest Postings
My friend NEEDS your HELP!
by Gizmo
11/26/08 12:21 AM
Useful PHP Functions & Code
by Gizmo
11/13/08 09:25 PM
UBBCode Tags
by Gizmo
11/13/08 09:25 PM
Topic Options
Rate This Topic
#19317 - 07/06/03 04:00 PM help with a php/mysql news script
UndeadBob Offline
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.

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

Top
Our Sponsors
Sponsor Our Sponsors

Sponsor Advertisements help keep UGN Security Online.



Support UGN Security by Purchasing our Sponsors Products.
Top  
#19318 - 07/06/03 04:36 PM Re: help with a php/mysql news script
pergesu Offline
Stoner Thugsta

Registered: 03/14/02
Posts: 1134
Loc: Pimpin the Colorizzle
You also need a value in your checkbox tags, I think.

Top
#19319 - 07/07/03 07:13 AM Re: help with a php/mysql news script
UndeadBob Offline
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."

Top
#19320 - 07/07/03 02:35 PM Re: help with a php/mysql news script
Predator Offline
Member

Registered: 03/01/02
Posts: 197
Loc: Belgium
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...

Top
#19321 - 07/07/03 07:59 PM Re: help with a php/mysql news script
ninjaneo Offline
Microwavable Pillow Tosser

Registered: 03/06/02
Posts: 229
Loc: CA, USA
?> " type=checkbox>

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

Top
#19322 - 07/07/03 10:02 PM Re: help with a php/mysql news script
pergesu Offline
Stoner Thugsta

Registered: 03/14/02
Posts: 1134
Loc: Pimpin the Colorizzle
actually, I think it's

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

Top
#19323 - 07/10/03 02:08 AM Re: help with a php/mysql news script
ninjaneo Offline
Microwavable Pillow Tosser

Registered: 03/06/02
Posts: 229
Loc: CA, USA
no bish, there feet! not single quotes! thats uber important! heh

Top
#19324 - 07/12/03 10:10 AM Re: help with a php/mysql news script
§intå× Administrator Offline
UGN Elite
*****

Registered: 12/03/02
Posts: 3252
Loc: here
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.
_________________________
My New site OpenEyes

Top
#19325 - 07/14/03 01:01 PM Re: help with a php/mysql news script
UndeadBob Offline
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."

Top
#19326 - 07/17/03 05:27 PM Re: help with a php/mysql news script
ninjaneo Offline
Microwavable Pillow Tosser

Registered: 03/06/02
Posts: 229
Loc: CA, USA
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...

Top
#19327 - 10/16/03 10:21 PM Re: help with a php/mysql news script
Paulo Breda Offline
Junior Member

Registered: 10/16/03
Posts: 1
Please help me to do a chat or post in javascript

Top
#19328 - 10/24/03 08:20 AM Re: help with a php/mysql news script
§intå× Administrator Offline
UGN Elite
*****

Registered: 12/03/02
Posts: 3252
Loc: here
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.
_________________________
My New site OpenEyes

Top



Moderator:  §intå×, Gizmo 
Featured Member
Registered: 02/11/08
Posts: 16
Forum Stats
6890 Members
44 Forums
11065 Topics
45844 Posts

Max Online: 677 @ 06/30/07 10:06 PM
Top Posters
Gizmo 6958
UGN Security 4115
§intå× 3252
IceMyst 1449
SilentRage 1273
Ice 1146
pergesu 1134
Infinite 1039
jonconley 954
Girlie 903
Newest Members
lucky vin, prEttyNDistress, AndrewKlilly, border, f4k3m3
6889 Registered Users
Who's Online
1 registered (Gizmo), 13 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Latest News
Update Humpday - Sept 26, 2008
by Gizmo
11/28/08 03:39 AM
Happy Holidays!
by Gizmo
11/27/08 09:09 AM
New Mailing
by Gizmo
11/24/08 01:30 PM
A special update...
by Gizmo
11/24/08 01:10 PM
Required Reading Update...
by Gizmo
11/07/08 11:36 AM


Donate
  Get Firefox!
Get FireFox!