1

Very new to all of this and having some issues using a line of code.

All i am trying to do is have my html file have a require statement that pulls a php file however it is not working. Please help.

<?php
require 'localhost/php/loginscreen.php';
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
jRogers
  • 37
  • 1
  • 10
  • Attach error code and environments to how it does not work – character Aug 22 '17 at 00:13
  • you should be getting an error for this; incorrect syntax. http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner Aug 22 '17 at 00:15
  • Please read the documentation on that http://php.net/manual/en/function.require.php and try again. – Funk Forty Niner Aug 22 '17 at 00:16
  • Strange as there is no error. as i refresh my html file nothing happens. – jRogers Aug 22 '17 at 00:17
  • *"Strange as there is no error. as i refresh my html file nothing happens"* - Now that makes this question unclear. Just how exactly are you trying to use this; as `http://localhost` or as `file:///`? and what type of file extension? You're not using an `.html` as a base file, are you? – Funk Forty Niner Aug 22 '17 at 00:17
  • Yep i read this earlier and tried as the file is in a different folder however still nothing – jRogers Aug 22 '17 at 00:19
  • Damm! yes its me being dumb, i was using the old html base file instead of the php one. sorry to waste your time – jRogers Aug 22 '17 at 00:22
  • @jRogers Well, I didn't think it was dumb, just something you may not have remembered/noticed. You didn't waste our time; least not mine and I've posted an answer below if you wish to mark it off as solved. It's voluntary but it does inform everyone that the question was solved. Welcome to Stack Overflow. – Funk Forty Niner Aug 22 '17 at 00:26

1 Answers1

0

"All i am trying to do is have my html file have a require statement that pulls a php file however it is not working".

That to me suggests that you're using an .html file as a base file to pull in an .php file.

Unless you've instructed your server to treat .html files as PHP, you would need to rename that file to a .php extension.

Edit. Consult the following Q&A on Stack on how to do this:

Your syntax for require 'localhost/php/loginscreen.php'; is incorrect.

You would need to either use a full system path: (as an example, replace that with your system path).

require '/var/usr/public/php/loginscreen.php';

or a relative path:

require 'php/loginscreen.php';

and using http://localhost rather than a possible file:/// url in the browser.

"Strange as there is no error. as i refresh my html file nothing happens."

Had you viewed your HTML source, you would have most likely have seen code, rather than parsed (PHP) directives. That would have been the reason why you did not see any errors, least not php-wise.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141