Skip to main content

Posts

Showing posts from December, 2013

Testing variables with PHP

First, we'll take a look at how to display what's in your variables. We're going to be viewing our results on a web page. So see if you can get this script working first, because it's the one we'll be building on. Using a text editor like Notepad, or your PHP software, type the following. (You can copy and paste it, if you prefer. But you learn more by typing it out yourself - it doesn't really sink in unless you're making mistakes!) <html> <head> <title>Variables - Some Practice</title> </head> <body> <?php print("It Worked!"); ?> </body> </html> Software Developer  Ishan When you've finished typing it all, save the page as variables.php. Then Run the script. Remember: when you're saving your work, save it to the WWW folder, as explained here. To run the page, start your browser up and type this in the address bar:  http://localhost/variables.php If you'v

String Variable in PHP

$coats1 = "Winter Coats"; Again, our variable name starts with a dollar sign ($). We've then given it the name coats1. The equals sign follows the variable name. After the equals sign, however, we have direct text - Winter Coats. Then you can also put text into your variables. Assume you want to know something about the coats you own. Are they Winter coats? Jackets? Summer coats? You decide to catalogue this, as well. You can put direct text into your variables. You do it in a similar way to storing numbers: But notice the double quotation marks around our text. If you don't surround your direct text with quotation marks, then you'll get errors. You can, however, use single quotes instead of double quotes. So you can do this: $coats1 = 'Winter Coats'; But you can't do this: $coats1 = 'Winter Coats"; In the above line, we've started with a single quote and ended with a double quote. This will get you an e