I read what simplypixie posted and was using the simplest version of his answer i.e. checking everything worked before introducing the $localhost variable.
The code I posted in my first post was the first element of code. I then realised there was a second element that referred to http://localhost so I amended it in line with the post from simplypixie assuming (maybe incorrectly) that I could exchange the commands for
I used the code from simplypixie in the first section but when I came to the second section which is now producing the error the original code was slightly so I amended it in line with simplypixie's example of how to add in an OR.
I don't know how to progress this as my knowledge is obviously limited and I am trying my best to explain what I have done and what problems are occurring.