![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
![]() |
Edit database entries with form
For each of my blog entries, I want to be able to click a link underneath it and for it to open a page with a form to edit the message. When clicking the link, it takes the user to www.abc.com/blog.php?edit= and then has the blog entries id number. So far, I've tried to retrieve the data from the database and have it in a text area ready for editting, this is my code:
PHP Code:
|
|
|
|
|
|
PM User | #2 |
|
Regular Coder ![]() Join Date: May 2009
Location: Horn Toad Ville, CA
Posts: 144
Thanks: 7
Thanked 30 Times in 30 Posts
![]() |
Looks like just few minor syntax errors. Mainly you are trying to get the blog variable instead of the edit for the $id.
PHP Code:
PHP Code:
Last edited by Coyote6; 11-07-2009 at 07:30 AM.. |
|
|
|
| Users who have thanked Coyote6 for this post: | Kineas (11-07-2009) |
|
|
PM User | #3 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
![]() |
Thanks for the reply, that's working great. Now all I need is for the database entry to be updated when the user clicks submit. I'm guessing I would have to make a seperate php file that it directs to when submit is clicked, and would possibly be similar to code that adds to the database but has CHANGE in there somewhere?
|
|
|
|
|
|
PM User | #4 | ||
|
Master Coder ![]() Join Date: Mar 2007
Location: God's own country
Posts: 8,976
Thanks: 142
Thanked 1,192 Times in 1,184 Posts
![]() ![]() ![]() ![]() |
Quote:
Code:
echo "<input type=\"submit\" value=\"submit\"
PHP Code:
__________________
Quote:
|
||
|
|
|
|
|
PM User | #5 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
![]() |
I'm almost there now, when the form is submitted, it uses POST to transfer the data held in $_POST['editid'], $_POST['edittitle'], and $_POST['editmessage'].
Now all I need is the mysql command to change the title to edittitle and message to editmessage where id = editid. I tried the following code, but it keeps throwing an error. PHP Code:
Last edited by Kineas; 11-07-2009 at 03:22 PM.. |
|
|
|
|
|
PM User | #6 | |
|
Master Coder ![]() Join Date: Mar 2007
Location: God's own country
Posts: 8,976
Thanks: 142
Thanked 1,192 Times in 1,184 Posts
![]() ![]() ![]() ![]() |
Try
PHP Code:
PS: Your query is susceptible to sql injection
__________________
Quote:
|
|
|
|
|
| Users who have thanked abduraooft for this post: | Kineas (11-07-2009) |
|
|
PM User | #7 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
![]() |
Thanks. I'm not too bothered about sql injection as the website is for a university assignment, and won't be actually holding any important data, nor will anyone actually know the url to it apart from me, but thanks anyway.
|
|
|
|
|
|
PM User | #8 | |
|
Master Coder ![]() Join Date: Mar 2007
Location: God's own country
Posts: 8,976
Thanks: 142
Thanked 1,192 Times in 1,184 Posts
![]() ![]() ![]() ![]() |
But still, if you submit any title or message having characters like single-quotes,double-quotes etc, your query will fail.
__________________
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|