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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.