Now that we're retrieving the article that we want to edit we need to display the farm so that we can
edit the articles details.
We've already got a farm for adding a new article that contains all the articles fields so we can use
that again.
We dont want to repeat ourselves.
So let's extract the code for the farm out into a file that we can share between adding and editing
an article let's create a new file in the includes folder and call it Article farm.
Doug P. HP.
We want to include the code that displays errors.
So we'll copy everything from here to the end of the FOB.
We'll then paste that in the new file.
Now at the moment the button to save the farm says that.
So let's change that to save.
Which is valid for both.
Adding a new article and saving changes to an existing one back in the new article script.
We can now replace what we've extracted
with a require of the file we extracted it to.
In the browser.
This still works including the validation and re displaying values with our ready entered when we submitted
the farm.
Now we can do the same in our edit article script will copy this including the header and footer
and paste it here.
All we need to change is the subheading to say edit like that.
If we open the edit page in a browser we see the farm but we're getting error messages inside each of
the controls.
This is because the farm is expecting variable's called Title content and published out.
However the data coming from the database is in an associative array so let's assign values to the expected
variables.
Once we've got the article like that.
Now in the browser we see the form with the values of the article we are editing inside the input controls.
Going back to the article page.
If we supply an idea of an article that doesn't exist
we get a message saying article not found.
However if we do the same with the edit article script we get an empty farm.
If the idea isn't passed in the query string let's output a message and exit the script for now.
Likewise if the get article function returns NULL which the If statement will understand as false will
do the same thing.
Outputting a message and exiting the script.
So this still works if we pass in a valid I.D. in the query string.
But if we pass in the idea of an article that doesn't exist we get one error message and if we remove
the idea from the query string all together we get the other error message.