Using phpmyadmin, i've migrated my website's files and tables from localhost to server.
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
).
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.