Jump to content

'require' in PHP


Recommended Posts

Hello. I'm new to this community and I have just recently started learning PHP.

I have run into the problem that the require statement doesn't seem to work:

 

HTML 1:phplesson23.tmpl.php

<!doctype html><html><head><style>li { list-style: none;}</style></head><body><h1>Join me in my journey to conquer the world!</h1><form action="" method="post"><?php if ( isset($status) ) echo $status; ?><ul><li><label for="name">Your name:</label><input type="text" name="name"></li><li><label for="email">Your email:</label><input type="text" name="email"></li><li><input type="submit" name="SIGN UP"></li></ul></form></body></html>

HTML 2: phplesson23.php

This is the one with the require statement.

 

<?php if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {$name = trim($_POST['name']);$email = trim($_POST['email']); if ( empty($name) || empty($email) ) {$status = 'Provide a name and valid email.'}} require 'phplesson23.tmpl.php';?>

What am I doing wrong?

Link to post
Share on other sites

What happens when you delete the ref to ".tmpl"?

 

Or, in a separate script run just the require statement?

Link to post
Share on other sites

Thank you for the replies and I solved it. I tried running the require statement in a separate script and it worked fine so I looked over it for the 6th time and I realised there was no ';' at the end of 'Provide a name and valid email.'

 

I can't believe I missed it when it was such a simple problem. I checked this thing so many times yesturday.

Link to post
Share on other sites

If you didn't see an error message for that, it sounds like PHP is either ignoring errors or sending everything to an error log. If this is on your computer, those settings are in php.ini. For development, you'll probably want to set display_errors to on and error_reporting to E_ALL.

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...