meemoe_uk Posted June 13, 2015 Share Posted June 13, 2015 hi all, total beginner here, Just trying to get my first php programs to work <?phpecho " hello world " ;?> doesn't print anything.... *** <html> <head> </head> <body> <?php print "<h1> hello </h1>"; // abcdedfg ?> </body></html> *** is suppose to print " hello " what i get is " hello "; // abcdedfg ?> " if i don't use the <h1>, it prints nothing. i run these scripts by opening them with a right mouse clcik on their windows file icon, and opening with firefox. maybe my settings aren't set right help plz Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/ Share on other sites More sharing options...
mac_gyver Posted June 13, 2015 Share Posted June 13, 2015 php is a web server-side scripting language. you need to request the page using a url on a web server. you can install a web server on your local computer to learn and develop php code. there are all-in-one AMP (Apache, Mysql, Php) packages you can find and install to do this. Xampp from apachefriends.org is probably the most common package. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513797 Share on other sites More sharing options...
meemoe_uk Posted June 13, 2015 Author Share Posted June 13, 2015 I have apache and mysql servers running on xampp v3.2.1, i'm guessing my php script running in firefox and the xampp server are not linked. So I'll look for ways to make them aware of each other. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513798 Share on other sites More sharing options...
meemoe_uk Posted June 13, 2015 Author Share Posted June 13, 2015 Ok, I've tried running my programs from the apache shell prompt ,and i get the same results. Perhaps something else is wrong Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513799 Share on other sites More sharing options...
QuickOldCar Posted June 13, 2015 Share Posted June 13, 2015 Is the script saved with a .php extension? If you save as htm or html the server needs to be configured to parse php. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513802 Share on other sites More sharing options...
blmg2009 Posted June 13, 2015 Share Posted June 13, 2015 I would suggest setting up a free hosting account using freehostia or something; Then use a free sub domain and test your code there; It's most likely you've not correctly set up your testing enviroment. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513803 Share on other sites More sharing options...
Ch0cu3r Posted June 13, 2015 Share Posted June 13, 2015 It sounds like you maybe loading your .php files directly into your web browser (ie the url address starts with file://C:/User/xxx....) This is the incorrect way for testing your php code. I have apache and mysql servers running on xampp v3.2.1, All your web site files needs to be saved in XAMPP's htdocs folder (eg C:\XAMPP\htdocs). You then proceed to http://localhost to to test your php code. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513808 Share on other sites More sharing options...
meemoe_uk Posted June 13, 2015 Author Share Posted June 13, 2015 Is the script saved with a .php extension? If you save as htm or html the server needs to be configured to parse php. No it was a .html extension. When i change it to .php extension and run it from the apache shell prompt, i get a message from windows saying it doesn't know how to run it, and plz select a program to recognise how to run it. >I would suggest setting up a free hosting account using freehostia or something That feels like cheating. All the guides say you can do it from your own machine as localhost, and several youtube tutorials do it from their own machine as the localhost too. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513810 Share on other sites More sharing options...
meemoe_uk Posted June 13, 2015 Author Share Posted June 13, 2015 It sounds like you maybe loading your .php files directly into your web browser (ie the url address starts with file://C:/User/xxx....) This is the incorrect way for testing your php code. All your web site files needs to be saved in XAMPP's htdocs folder (eg C:\XAMPP\htdocs). You then proceed to http://localhost to to test your php code. You're right, i was loading them straight into firefox. Ok, so now I've moved my php programs into the C:\xampp\htdocs folder. Then i went to http://localhost. But i didn't see any ' run php script ' button or prompt. Strikes me as odd, because that xampp page seems to have a lot of functionality, why did they leave out a 'run php script' function? so I just drag dropped my php code file windows icon into the browser ontop of the xampp page, and got the same blank page result. Still isn't working :/ Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513811 Share on other sites More sharing options...
QuickOldCar Posted June 13, 2015 Share Posted June 13, 2015 so I just drag dropped my php code file windows icon into the browser ontop of the xampp page, and got the same blank page result. Still isn't working :/ Dragging the icon is still opening as were. Try http://localhost/your_script_name.php Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513812 Share on other sites More sharing options...
meemoe_uk Posted June 13, 2015 Author Share Posted June 13, 2015 >Try http://localhost/your_script_name.php It worked !! thanks for the patience to get a noob started. Now i can start to experiment with php more independantly. Link to comment https://forums.phpfreaks.com/topic/296792-mega-noob-question-1st-php-program/#findComment-1513814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.