PDA

View Full Version : Help with PHP? +REP!



myke
13-01-2007, 04:51 PM
ok, I am currently learning PHP on w3schools however I have entered what I want into a PHP file called index.php and opened in Mozilla Firefox

here's my code:


<HTML>
<HEAD>
<title>PHP Test File</title>
<style type="text/css">
<!--
body {background: #6699cc;}
-->
</style>
</head>

<body>
<?php
$txt="BLOB";

echo $txt to you;?>


</body>
</html>and here's the one on the w3schools:


<html>
<body> <?php
$txt="Hello World";
echo $txt;
?> </body>
</html>both of which when I open in Mozilla Firefox show nothing, what do I do?

Splinter
13-01-2007, 05:33 PM
could be because you have installed php on you pc. Its a server side language not client side so therefore needs to run on a machine with php installed..

timROGERS
13-01-2007, 05:33 PM
Same thing that I said to him on MSN. I walked him through setting up and using EasyPHP, so he's good now :D

Tomm
13-01-2007, 05:35 PM
Just for reference to any other people who view this:

You need some kind of server software (e.g Apache with PHP or IIS with PHP) to run PHP scripts. The server parses the PHP and returns HTML to the browser (e.g Firefox/Internet Explorer). The browser does not actually parse/run the PHP.

Heinous
13-01-2007, 10:57 PM
*Jumps in*

Also, you can't echo a variable and string without quotes, it returns a parse error

$txt="BLOB";

echo $txt to you;
Should be either.

$txt="BLOB to you";

echo $txt;
# Or
$txt="BLOB";

echo "{$txt} to you";

Dentafrice1
14-01-2007, 07:28 PM
<HTML>
<HEAD>
<title>PHP Test File</title>
<style type="text/css">
<!--
body {background: #6699cc;}
-->
</style>
</head>

<body>
<?
$txt = "BLOB";
echo "$txt to you";
?>
</body>
</html>


And are you saving it as .php and not .htm/.html?

Kevin

Tomm
14-01-2007, 07:39 PM
*Jumps in*

Also, you can't echo a variable and string without quotes, it returns a parse error

$txt="BLOB";

echo $txt to you;Should be either.

$txt="BLOB to you";

echo $txt;
# Or
$txt="BLOB";

echo "{$txt} to you";

Or even better idea:

Replace:


echo "{$txt} to you";

With:

echo '$txt to you';

Dentafrice1
14-01-2007, 07:42 PM
But if its not showing up.. if should error something.. its just blank.

I think he is saving it as .html

Mentor
14-01-2007, 07:47 PM
Or even better idea:

Replace:


echo "{$txt} to you";

With:

echo '$txt to you';
i find it cleaer just to seperate them more visually in code highlighting terms

echo $txt." to you";


ps. Check the sourse, is the php actualy showing in the sourse code? if so you ether dont have php installed or are useing the wrong exstention

Dentafrice1
14-01-2007, 09:57 PM
I think Carl he isnt saving the write extension

Heinous
14-01-2007, 10:04 PM
Or even better idea:

Replace:


echo "{$txt} to you";With:

echo '$txt to you';
It's a better habit to get into my way. ;)

Oh, and not forgetting variables don't pass in single quote echoes.

Dentafrice1
14-01-2007, 11:17 PM
they pass in

" ";
(" ");
and just echo $variable;

i think they work in ("");?

Mentor
16-01-2007, 07:58 PM
I think Carl he isnt saving the write extension

as far as i can tell the main problem is he isnt saving at all? not that hes saving it wrong o.0
Hes also not retrieving the data he probably needs to save at any point o.0

Agnostic Bear
31-01-2007, 12:10 PM
Or even better idea:

Replace:


echo "{$txt} to you";With:

echo '$txt to you';

And here's the proper PHP.net defined way on how to do it:

echo "$text to you";

And here's how I'd do it:

echo("$text to you");

ZAG
31-01-2007, 05:20 PM
I'd normally use



echo $text." is in the variable";
But if they all work, it doesnt really matter.

Want to hide these adverts? Register an account for free!