luckydog Posted April 20, 2007 Share Posted April 20, 2007 Just started with PHP but I am familiar with C++/C#. When I run: <HTML> <HEAD> <TITLE>FIRST PHP RUN</TITLE> </HEAD> <BODY bgcolor="0000ff"> <?php echo("This was written out by PHP"); ?> </BODY> </HTML> through IE or Firefox I get the right background color but no echo, no "This was written out by PHP". Tried "print" also but none of that happening either. If I run: <?php phpinfo(); ?> I get the PHP information page as expected. I'm working through the book PHP Game Programming by Matt Rutledge. When I run one of the pages of code that came with it they work fine. It's going to be hard to move on until I can get this resolved. Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/ Share on other sites More sharing options...
dustinnoe Posted April 20, 2007 Share Posted April 20, 2007 <?php echo "This was written out by PHP"; ?> print() uses parenthesis because it actually returns a value. echo returns nothing so no parenthesis. <a href="http://us.php.net/echo">more info</a> Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-233673 Share on other sites More sharing options...
Glyde Posted April 20, 2007 Share Posted April 20, 2007 <?php echo "This was written out by PHP"; ?> print() uses parenthesis because it actually returns a value. echo returns nothing. Actually, that has nothing to do with why it uses parenthesis. Print and echo are language constructs, so are include, require, include_once, require_once, etc. They are not actually functions and therefore do not need parenthesis surrounding the "parameters," however it should work fine even if you do have them there. In his case, that's not what is causing the problem. Try, on a blank page: <?php $array = array('my', 'test', 'array'); print "<pre>", print_r($array, true), "</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-233675 Share on other sites More sharing options...
luckydog Posted April 20, 2007 Author Share Posted April 20, 2007 Thanks Glyde- In IE I still got a blank page. In Firefox it printed, ", print_r($array, true), ""; ?> Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234105 Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 are you sure your a) using a php file, and b) your server supports php? Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234109 Share on other sites More sharing options...
kenrbnsn Posted April 20, 2007 Share Posted April 20, 2007 How are you invoking the script? Does the name of the script end with "php" or "html"? It should end with "php". Ken Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234139 Share on other sites More sharing options...
luckydog Posted April 20, 2007 Author Share Posted April 20, 2007 How are you invoking the script? Does the name of the script end with "php" or "html"? It should end with "php". From Notepad++ RUN->Launch in IE (or Firefox) or from IE File->Open... "are you sure your a) using a php file, and b) your server supports php?" The file extension is .php. Apache has run other php scripts without a problem. However, when I run this (from the CD that came with my book): <HTML> <HEAD> <TITLE>Processing All Form Elements</TITLE> </HEAD> <BODY BGCOLOR="#ffffff"> <FORM name="frm_Example" action="example04_02.php" method="post"> <table border="0" cellpadding="2" cellspacing="0"> <tr> <td align="left" valign="top"><b>Characters Name</b></td> <td align="left" valign="top"><input type="text" name="strCharacter"></td> </tr> <tr> <td align="left" valign="top"><b>Starting Amount of Gold</b></td> <td align="left" valign="top"> <select name="dblGold"> <option value="1000">1000</option> <option value="2000">2000</option> <option value="3000">3000</option> </select> </td> </tr> <tr> <td align="left" valign="top"><b>Starting Location</b></td> <td align="left" valign="top"> <input type="radio" name="strLocation" value="mountains">Mountains <input type="radio" name="strLocation" value="plains" checked>Plains <input type="radio" name="strLocation" value="swamp">Swamp </td> </tr> <tr> <td align="left" valign="top"><b>Equipment</b></td> <td align="left" valign="top"> <input type="checkbox" name="nEquipmentID[]" value="1" checked>Sword <input type="checkbox" name="nEquipmentID[]" value="2" checked>Chain Mail <input type="checkbox" name="nEquipmentID[]" value="2345" checked>Shield <input type="checkbox" name="nEquipmentID[]" value="4">Cross Bow <input type="checkbox" name="nEquipmentID[]" value="5">Arrows </td> </tr> <tr> <td align="left" valign="top" colspan="2"><input type="submit" value="Submit"></td> </tr> </table> </FORM> <?php if($_POST) { $strCharacter = $_POST['strCharacter']; $dblGold = $_POST['dblGold']; $strLocation = $_POST['strLocation']; echo("You Chose:<BR>$strCharacter<BR>$dblGold<BR>$strLocation<BR>"); $listvals = $_POST['nEquipmentID']; for($i=0;$i<count($_POST['nEquipmentID']);$i++) echo "Equipment ID $i=".$listvals[$i]."<br>\n"; } ?> </BODY> </HTML> Internet Explorer shows the form as expected but then prints: $strCharacter $dblGold $strLocation "); $listvals = $_POST['nEquipmentID']; for($i=0;$i\n"; } ?> at the end. Thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234233 Share on other sites More sharing options...
kenrbnsn Posted April 20, 2007 Share Posted April 20, 2007 That's your problem. PHP needs to be processed via the webserver. Do you have a local webserver running on your machine? If you do, you must invoke it via http://localhost/path/to/your/script.php. Next time you post code, please surround it with tags. I will edit you post to put those in. Ken Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234318 Share on other sites More sharing options...
luckydog Posted April 20, 2007 Author Share Posted April 20, 2007 DOH! I knew that. And 10-4 on the tags. Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234333 Share on other sites More sharing options...
dustinnoe Posted April 20, 2007 Share Posted April 20, 2007 <?php echo "This was written out by PHP"; ?> print() uses parenthesis because it actually returns a value. echo returns nothing. Actually, that has nothing to do with why it uses parenthesis. Print and echo are language constructs, so are include, require, include_once, require_once, etc. They are not actually functions and therefore do not need parenthesis surrounding the "parameters," however it should work fine even if you do have them there. In his case, that's not what is causing the problem. Try, on a blank page: <?php $array = array('my', 'test', 'array'); print "<pre>", print_r($array, true), "</pre>"; ?> print does act like a function in that it always returns a value. I don't know what I was thinking on the parenthesis though. Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234368 Share on other sites More sharing options...
Glyde Posted April 21, 2007 Share Posted April 21, 2007 <?php echo "This was written out by PHP"; ?> print() uses parenthesis because it actually returns a value. echo returns nothing. Actually, that has nothing to do with why it uses parenthesis. Print and echo are language constructs, so are include, require, include_once, require_once, etc. They are not actually functions and therefore do not need parenthesis surrounding the "parameters," however it should work fine even if you do have them there. In his case, that's not what is causing the problem. Try, on a blank page: <?php $array = array('my', 'test', 'array'); print "<pre>", print_r($array, true), "</pre>"; ?> print does act like a function in that it always returns a value. I don't know what I was thinking on the parenthesis though. ACTS like a function, and can be used by one, but is not. Print, as stated, is still a language construct. But that's unimportant, please make the post as solved. Quote Link to comment https://forums.phpfreaks.com/topic/47824-no-print-or-echo-newb/#findComment-234734 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.