timbo6585 Posted April 21, 2007 Share Posted April 21, 2007 hello all, i have a good foundation in HTML, no PHP knowledge. the script im about to show you someone kindly gave me. i copied and pasted it into notepad, saved it as a php, then opened it in firefox thinking it would work normal and i would just have to fill in the blanks. no such luck, it just comes up completely blank. i've tried tweaking a few things and the browser seems to get mad and just display the whole entire code making me know i screwed something up. my aim here is to just make a simple little script that will display a random fact every time the page is refreshed. here is the code, thank you for the help. <?php switch (rand(1,5)){ case "1": echo "html goes here. This is item 1"; break; case "2": echo "html goes here. This is item 2!"; break; case "3"; echo "html goes here. This is item 3"; break; case "4"; echo"html goes here. This is item 4"; break; case "5"; echo"html goes here. This is item 5"; break; } ?> Link to comment https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/ Share on other sites More sharing options...
trq Posted April 21, 2007 Share Posted April 21, 2007 Have you installed a web server and configured it to run php? Are you accessing the file via the address http://localhost/filename.php ? Link to comment https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/#findComment-234534 Share on other sites More sharing options...
timbo6585 Posted April 21, 2007 Author Share Posted April 21, 2007 :-[ :-[no... i thought i could just open it up in a browser and have it display fine like i can with HTML, regardless of whether or not it's a server. did i think wrong? i do have a PHP based forum that i use, simple machine forum, and can throw it in there just to get a look at it. Link to comment https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/#findComment-234535 Share on other sites More sharing options...
trq Posted April 21, 2007 Share Posted April 21, 2007 PHP is executed server side (not like html which is rendered via a browser), so yes, you need a web server. You can set one up on your local machine to test code on. Assuming your using a windows OS I would probably recommend setting up something like XAMPP. Otherwise, you'll need to install Apache and PHP separately. Link to comment https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/#findComment-234538 Share on other sites More sharing options...
timbo6585 Posted April 21, 2007 Author Share Posted April 21, 2007 okay i will look into those, thanks for the advice. i also stuck it in my forum to give it a try and it appears it is working, thanks for the info. -tim Link to comment https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/#findComment-234540 Share on other sites More sharing options...
trq Posted April 21, 2007 Share Posted April 21, 2007 Well, if your forum is working then you already have a server. (Assuming the forum is on your local machine). Link to comment https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/#findComment-234544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.