JkennG Posted August 19, 2016 Share Posted August 19, 2016 I have 2 php files and in my index file im just getting a function but its returning 2 echo's instead of just one. index.php <?php require_once 'config_db.php'; require_once 'database_class.php'; $db = new database($conDB); echo '<br/>'; $fetch = $db->getData(); ?> other file <?php include('index.php'); class database{ function __construct($conDB) { $this->conDB = $conDB; } function getData() { $clientIP = $_SERVER['REMOTE_ADDR']; echo $clientIP; $query = $this->conDB->prepare(" INSERT INTO `ip log` (`Address`) VALUES ('$clientIP') "); $query->execute(); } } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 19, 2016 Share Posted August 19, 2016 (edited) I do see that your second block of code is attempting to include the first as well as define its own 'database' class. Edited August 19, 2016 by ginerjm Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 19, 2016 Share Posted August 19, 2016 This looks like a circular dependency: Your index.php includes the database_class.php, but the database_class.php in turn includes the index.php. If you didn't have the require_once, you'd actually run into infinite recursion. In any case, the script layout is very confusing and poor. A class file shouldn't do anything but define a class. It should definitely not run some index.php script with side effects. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.