Jump to content

No print or echo (nEwB)


luckydog

Recommended Posts

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

 

Link to comment
Share on other sites

<?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>";
?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.