If we want to edit or delete any of the posts we have submitted, were going to need an admin list of all the posts entered with links to either edit or delete that post.
The below code is the complete code for the admin list page (/admin/list.php):
Its not very pretty, but it displays all the latest posts in descending order, and presents two links next to each title to either edit or delete the post.
the code: <a href='ed.php?id=$send->id'></a> basically calls the edit script into play, while sending the "id" variable with the link. This allows us to edit or delete the post where id=xx.
Edit
The next bit of code is quite like the initial add script that we wrote earlier in the tutorial It connects to the databse and selects the record requested. So if you press edit on id 1, we see a form filled with all the information saved in the first news post.
The edit script - save as (/admin/ed.php):
There we logged into the database and collected all information on id number xx, then displayed the information in a form ready for editing. Next, we need to check if the form has been submitted, and were there any errors? If not, update the record in the db with the new values or halt if any error encountered.
That updated the databse for id number xx with the new values entered into the form.
Delete
And finally, the admin needs to delete posts. this page is only a few lines of code:
With the code sample shown above, we have connected to the database and asked it to delete the article with id number xx.
Subject: "Problem help"
Date: Nov 16 2008 at 10:31 am
I am having a
problem at the
del.php
page.
This sentence
does not work:
$query =
"DELETE
FROM news WHERE
id =
'$id'";
.... Its like
my script does
not recieve the
id or
something, I
get no error
message but the
row does not
get deleted
from my table.
If i use this:
$query =
"DELETE
FROM news WHERE
id =
'1'";
the row gets
deleted from
the table but
then the entire
of the script
is gone.
Im having the
same problem at
the r.php
file.... This
site just
returns
nothing.
I have simply
copy pasted all
the code in the
tutorial and
changed the db
login
variables.