Hi im new to coding and as im sure youll tell my knowledge is very limited!
I have started reading PHP and MySQL Novice to Ninja. Im on chapter 3 and struggling with the ‘Passing variables in links’ task. Ive created a HTML file with the following:
This displays the link “Hi I’m Kevin”. Thats all fine but when i click on it, it should take me to a page saying “Welcome to our website Kevin” using the following code:
In order to make it work, you need to be using the second type of link - opening via the http://localhost/ url. If you just double-click the html file in your explorer window, it will use the file associations to open it in the browser rather than via the server, which will mean that it doesn’t process the PHP code.
Ahh ok, that makes sense. It said in the book load the file in your browser - so i double clicked it as you said. So to make it work i had to type in the link “http://localhost/name.html”, so i’ll have to type it in future also?
With a link like “name.php?whatever”, the browser looks at it and says “There’s no domain information (www.whatever.com) in this link. So i’ll use whatever domain i’m CURRENTLY on. There’s no Directory information (link doesnt start with a /) so i’ll use the current directory also.”
That leads you to file:///C:/xampp/htdocs/ if you opened the original page as a file in that directory.
@rhi519 - Notice the protocol being used in the browser address, “file://”? This is the protocol used when you open a file directly from your hard drive. For testing web pages, you need to check that you’re using the “http://” protocol. In other words, using the localhost testing web service on your computer.
The link’s href value that you’re using, “name.php?name=Kevin”, is called a document relative value. The value is relative to the current URL in the browser. An example of an absolute value would be “http://localhost/name.php?name=Kevin”. Absolute values will work regardless of protocol. However the relative value is best for portability, i.e going live. Otherwise you’d be stuck with a bunch of links to localhost, which wont work of course.