Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

[web] Problems with require() in PHP

Started by Sonnenblume 5 replies 750+ views
Original Post
Sonnenblume
Sonnenblume
Hi There I was transferring a script that worked fine on my laptop to my host provider, when I discovered that the page wasnt functioning as expected. After examining the source, I discovered it was failing to execute the require() statement. Here is the code itself Questionnaire'; require('questionnaireHeader.php'); echo' The Script require() is calling looks like this '; //Gets the activity from the previous page $activity = $_POST['activity']; //Function which creates the drop down menu for the user to select their //activity function dropDownMenu($db) { $query = "select * from activity"; $result = $db->query($query); $num_results = $result->num_rows; echo''; } ?> Going by the fact it works fine on my own machine but not the host's, im guessing its a configuration setting in php.ini, but if its something simple then please let me know :) Both systems are running PHP 5. Thanks.
dave
dave
How come the require() at the top is not within php tags, nor is the echo on the following line.

Also, i believe it is good practice to require all files before any HTML is output, ie right at the top of the page.

Dave
Sonnenblume
Sonnenblume
The code I included is actually situated between tags, I just included the section that was causing me bother rather than create one massive post.
dave
dave
One further suggestion i can give is to use require_once() or include_once() instead of its non-onced version.

Dave
Sonnenblume
Sonnenblume
I figured out what it was, it was objecting to me using require to call my connection script. Its a problem ive never encountered before.

Does anyone know why that happened? As far as I knew you could use require() to call a script which also contained a require() statement.
dave
dave
I've never had a problem with the _once()'s, i guess i never encountered your problem either.

Dave
markr
markr
I assume the two machines are identical in every other respect, e.g. running same version of PHP on same web server, same OS version etc?

What error do you get on the PHP error log. Can you paste it?

Mark

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.