Jump to content

'require' in PHP


newbiestarter

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 comment
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 comment
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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...