deleting recordset from database via an admin page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Richking
Forum Newbie
Posts: 12
Joined: Thu Mar 09, 2006 8:14 am

deleting recordset from database via an admin page

Post by Richking »

Hi there
I've got a form for someone to add news items to a page which is fine. On an admin page I'm displaying the news items and want to put a delete button by each so they can be deleted when redundant.
I've tried doing this by identifying the id in the table and then deleting it but I'm going round in circles...
Any suggestions?
Thanks in advance
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What have you tried up to now. show you code
Richking
Forum Newbie
Posts: 12
Joined: Thu Mar 09, 2006 8:14 am

Post by Richking »

What I have is a repeated region to show the results. Where I'm confused is where to tag the $query, which would be

Code: Select all

$query = "DELETE FROM news WHERE .....";
What would be ideal is to have a setion at the end where the user can enter in a form field the id number of the row that they want to delete, but I'm stuck on how to phrase that within the query above.
Richking
Forum Newbie
Posts: 12
Joined: Thu Mar 09, 2006 8:14 am

Post by Richking »

to just expand that

Code: Select all

<form name="form1" id="form1" method="post" action="">
        <input name="idnumber" type="password" id="idnumber" />
        <input name="Delete Item" type="submit" id="Delete Item2" value="Delete Item" />
  </form>

Code: Select all

<?php> mysql_select_db($database_Royalbluecms, $Royalbluecms);
	  $query = "DELETE FROM news SET id WHERE id="idnumber"";
	  $result = "mysql_query($query) or die ("Couldn't execute query");
	 
	  <?>
is returning this error

Parse error: syntax error, unexpected T_STRING in C:\apachefriends\xampp\xampp\htdocs\Royalbluecms\admin.php on line 209
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Should be pretty obvious with syntax highlighting.

Code: Select all

$query = "DELETE FROM news SET id WHERE id=".$idnumber;
$result = mysql_query($query) or die ("Couldn't execute query");
Richking
Forum Newbie
Posts: 12
Joined: Thu Mar 09, 2006 8:14 am

Post by Richking »

it's coming back "couldn't execute query"....
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

your query is wrong

should be something like

Code: Select all

$query = "DELETE FROM news WHERE id=".$idnumber;
you may wanna change the execution line to this for a more informative error message

Code: Select all

$result = mysql_query($query) or die (mysql_error());
Richking
Forum Newbie
Posts: 12
Joined: Thu Mar 09, 2006 8:14 am

Post by Richking »

that's nailed it thanks!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$query = "DELETE FROM news WHERE id=".intval($idnumber);
if your taking that $idnumber straight from the form, I would recommend doing to ensure that it is a number.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I suggest that you make a backup first, and then try "1 OR 1=1" as value...
Post Reply