When editing an existing article if we submit valid values the validation passes.
Now we know how to up day to record using ESC.
Well we can use these values to update the article in the database so we avoid Escuela injection as
before.
We'll use a prepared statement in the new article script here.
We're using it prepared statement to insert a new record.
We'll be doing something similar so we can copy this code.
And paste it here in our edit script.
We don't need to call the Get dbe method to get the database connection as we are ready.
Doing it at the top here so we can delete this line.
Next let's change the insert statement into an update one with place holders for the fields were updating
and also for the eidy in the WHERE clause.
Then we prepare the statement output.
Any error if there is one and if all is well we set the publish date to know if it's empty and then
we bind the parameter so the values we've got from the farm.
However in addition to the fields we were updating.
We've also got a place holder for the idea of the article we want to update in our esky well.
At the top of the script we're setting the variables for the article we're editing from the data we
get back from the database.
So let's add another one for the idae then back down here where we're binding the parameters we can
add this to that function call making sure we bind it as an integer just as we did when selecting a
record.
If this executes successfully we dont need to call this function to get the I.D. of the inserted rijkaard
as we're updating that other than inserting.
Then we redirect to the article page as before passing in the idees variable which we just set at the
top.
Let's give that a try.
Let's change some of the articles current values and submit the farm we're redirected back to the article
page and the.
Data has been changed so we've successfully updated the data using the update statement.
Finally let's add a link from the article page here to the edit page we just added Let's add it here
just after the articles data has been displayed.
We need to pass in the idea of the article in the query string which we can get from the article rijkaard
in the same way that we're getting the title and the content.
We dont need to use the h.t. EMAIL special chars function though as this will always be a number.
In the browser if we click on an article we have a link to edit it.
We can make some changes.
And save those changes to the database.