Jump to content

Why won't this simple code work?


xxreenaxx1

Recommended Posts

Hey,

 

I tired to run this. It so simple but I don't know whats wrong with it

 

<HEAD>
<TITLE>Welcome</TITLE>
</HEAD>
<BODY>
<P>Hi,
<?php

$firstname = 'Ragena';
echo '$firstname';
// PHP finishes here, now back to HTML
?>
Your first name is <?php echo
$firstname; ?>.</P>
<P>The time now is <?php echo date(‘Y-m-d H: -- i:s’);
?></P>
</BODY>
</HTML>

Link to comment
https://forums.phpfreaks.com/topic/226055-why-wont-this-simple-code-work/
Share on other sites

Try this...

And get a better date snippet.

and start <?php on the beginning of the line.

 

<HEAD>
<TITLE>Welcome</TITLE>
</HEAD>
<BODY>
<P>Hi,
<?php

$firstname = 'Ragena';

// PHP finishes here, now back to HTML
?>
Your first name is
<?php
echo $firstname;
?>.
</P>

</BODY>
</HTML>

echo '$firstname';

 

You need to either use double quotes "..." or no quotes.  Variables are not evaluated in single quotes.

 

date(‘Y-m-d H: -- i:s’)

 

You can't use those funky quotes.  PHP recognizes normal single or double quotes '...' or "..."

 

 

Also in the future, try to be more descriptive of the problem.  Explain what you expect to be happening and what it is not doing that you expect. Explain what it is doing instead.  Just saying "It doesn't work" is not descriptive. 

 

Everything else is syntactically correct.

<?php date_default_timezone_set('Europe/London'); ?>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<p>Hi,
<?php
  $firstname = 'Ragena';
  echo $firstname;
  // PHP finishes here, now back to HTML
?>
</p>
Your first name is <?php echo $firstname; ?>.</p>
<p>The time now is <?php echo date('Y-m-d H: -- i:s');
?></p>
</body>
</html>

 

Try using the code above, you didn't have proper apostrophes in your code.

Also you should use date_default_timezone_set(); as you shold receive a warning if you have display errors on.

 

Regards, PaulRyan.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.