1

Using phpmyadmin, i've migrated my website's files and tables from localhost to server.

enter image description here

How i've set it up is: the user has to log-in (checklogin.php) with username and password to get to the homepage (index.php).

enter image description here

enter image description here

Below is the content of the checklogin.php:

<?php
$host="localhost"; // Host name 
$username="garbo49"; // Mysql username 
$password="turf"; // Mysql password 
$db_name="garbo49"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "loginsuccess.php"
$_SESSION['myusername']= "myusername"; 
$_SESSION['mypassword']= "mypassword"; 
header("location:loginsuccess.php");
}
else {
echo "Wrong Username or Password";
}
?>

Now i am able to sign-in (no errors are generated), and my homepage (index.php) displays (or at least the static information does) - but only as long as i remove include ('setup.php') from the index.php file. Otherwise, it shows a blank page. Setup.php is the file that includes database, localhost, username and password details.

All the details in the setup.php match up with that of the new database (which are the same details specified in the loginpage shown above). Here are the contents of setup.php:

<?php
$hn = 'localhost';
$db = 'garbo49';
$un = 'garbo49';
$pw = 'turf'; 

#DB Connection:
 $conn = new mysqli($hn, $un, $pw, $db);
 if ($conn->connect_error) die($conn->connect_error);

#Functions:
require_once ('function.php');


#Section setup:
$newsrow = news_data($conn);
$reviewsrow = reviews_data($conn);
$blogrow = blog_data($conn);
$reciperow = recipe_data($conn);
$foodiqrow = foodiq_data($conn);
$eventsrow = events_data($conn); 


//$result->close();
//$conn->close();

?>

Why is the server refusing to read the setup.php, when all the details correspond with the new database? Would appreciate any insight.

RESOLUTION: With guidance from William Lee (comments) - a look at the errorlogs revealed the intervening error was in fact: Call to undefined function mysqli_fetch_all(). So I guess that meant my wonderful host wasn't offering msqli support (its PHP installation was not compiled with mysqlnd). So I used $result->fetch_assoc() instead. A good explanation here.

Community
  • 1
  • 1
Agni Scribe
  • 252
  • 3
  • 18
  • what do you get if you dump get_included_files()? – William Lee Feb 16 '16 at 17:31
  • @ William Lee in which file should i run that? – Agni Scribe Feb 16 '16 at 17:39
  • right after trying to include your setup.php – William Lee Feb 16 '16 at 17:41
  • running this should give you the path of the included files, it might be possible that your script is including the setup.php from another path. – William Lee Feb 16 '16 at 17:43
  • It gives a server error 500 (where before -with just the include setup.php it gave a blank page) – Agni Scribe Feb 16 '16 at 17:45
  • 1
    try putting this in the first line of your code: "error_reporting(E_ALL);" and then "ini_set('display_errors', 1);" and try to simulate the blank page – William Lee Feb 16 '16 at 17:47
  • sorry, that was not an error message of the current time - basically there was no error output and the browser was a blank page again – Agni Scribe Feb 16 '16 at 18:03
  • Well, the log says it is trying to include something in "hood/setup.php". Since it is relative, I recommend you to put the full path, as the answer from Dimitrios says. The absolute path will avoid you this kind of trouble! – William Lee Feb 16 '16 at 18:13
  • @yes that was an earlier time when I had put setup.php in the hood. i since took it out and its in the same level as index.php – Agni Scribe Feb 16 '16 at 18:14
  • even with error_reporting and display_errors on it shows a blank page? – William Lee Feb 16 '16 at 18:17
  • yes, it shows a blank page since i'm adding the setup.php before that(which i guess breaks off before the error reporting). – Agni Scribe Feb 16 '16 at 18:24
  • 1
    the setup.php must be AFTER the error_reporting and ini_set, so that it'll affect the setup.php and show us what's troubling you. – William Lee Feb 16 '16 at 18:28
  • Fatal error: Call to undefined function mysqli_fetch_all() in /home/garbo49/public_html/kitchens.com/function.php on line 20. This is a file that has been called by setup.php & that mysqli_fetch_all() is used there as part of: function news_data($conn) { $query = "SELECT * FROM news ORDER by newstrack DESC LIMIT 3"; $result = $conn->query($query); // $row = $result -> fetch_array(MYSQLI_BOTH); $row = mysqli_fetch_all($result, MYSQLI_ASSOC); return $row; } – Agni Scribe Feb 16 '16 at 18:33
  • 1
    There's your problem, your host does not have mysqli support – William Lee Feb 16 '16 at 19:02
  • @WilliamLee, yes just found out - have replaced that with: $data = []; while ($row = $result->fetch_assoc()) { $data[] = $row; } and it works! thanks for guiding me on this. – Agni Scribe Feb 16 '16 at 19:05
  • You're very welcome. Can you edit your post with the resolution? – William Lee Feb 16 '16 at 19:08

1 Answers1

1

Is it is a VPS Server or upload to a shared hosting via FTP then try to set the +x permission to your script. (Supposing running linux)

Also when you are on VPS try to set on www-data user (when not using su php).

Secondly check the paths on when you include something. When moving between server is is nice to make sure that the file is included is the correct one. Usually when I develop I try to generate dynamically the full path of the script so I will be 100% sure that the script will be included regardless the path.

PHP Magic constants may Help: http://php.net/manual/en/language.constants.predefined.php

Also you can check the server logs in order to figure out what wrong happened. Depending when you use Plesk or Cpanel or a custom configuration you should:

Also Enable error reposrting on php with: http://php.net/manual/en/function.error-reporting.php

Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164