How to solve this?
Copy "db/tables.sql" from the CMS package, then put it inside "db" folder on your server.
prepare($query);
$stmt->execute();
}
function _insert_to_setting($conn, $name, $type, $category, $label, $tooltip, $value){
$sql = "SELECT id FROM settings WHERE name = :name";
$st = $conn->prepare($sql);
$st->bindValue('name', $name, PDO::PARAM_STR);
$st->execute();
$row = $st->fetch(PDO::FETCH_ASSOC);
if(!$row){
// Data is not exist
$sql = "INSERT INTO settings (name, type, category, label, tooltip, value) VALUES (:name, :type, :category, :label, :tooltip, :value)";
$st = $conn->prepare($sql);
$st->bindValue('name', $name, PDO::PARAM_STR);
$st->bindValue('type', $type, PDO::PARAM_STR);
$st->bindValue('category', $category, PDO::PARAM_STR);
$st->bindValue('label', $label, PDO::PARAM_STR);
$st->bindValue('tooltip', $tooltip, PDO::PARAM_STR);
$st->bindValue('value', $value, PDO::PARAM_STR);
$st->execute();
}
}
$db_name = preg_replace('~[^A-Za-z0-9?-_-.]~','', $_POST['db_name']);
$db_host = preg_replace('~[^A-Za-z0-9?-_/\-.]~','', $_POST['db_host']);
$db_user = preg_replace('~[^A-Za-z0-9?-_-.]~','', $_POST['db_user']);
$db_password = str_replace(' ','',$_POST['db_password']);
if($db_name != $_POST['db_name'] || $db_host != $_POST['db_host'] || $db_user != $_POST['db_user'] || $db_password != $_POST['db_password']){
echo '
Error. Unsupported characters detected.
';
header('Refresh: 3; url=install.php');
} else {
try {
$conn = new PDO("mysql:host=".$db_host.";dbname=".$db_name, $db_user, $db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
create_tables($conn);
$json = json_decode(file_get_contents('db/settings.json'), true);
foreach ($json as $item) {
_insert_to_setting($conn, $item['name'], $item['type'], $item['category'], $item['label'], $item['tooltip'], $item['value']);
}
$_SESSION['db_name'] = $db_name;
$_SESSION['db_host'] = $db_host;
$_SESSION['db_user'] = $db_user;
$_SESSION['db_password'] = $db_password; ?>
Database connected successfully
Failed. Can\'t connect to database.
';
header('Refresh: 3; url=install.php');
};
$conn = null;
}
} elseif(isset($_POST['admin_user'])){
$admin_user_ori = $_POST['admin_user'];
$admin_user = preg_replace('~[^A-Za-z0-9-_]~','', $_POST['admin_user']);
if($admin_user == $admin_user_ori){
$admin_password = password_hash($_POST['admin_password'], PASSWORD_DEFAULT);
$filecontent = file_get_contents('connect-sample.php');
$filecontent = str_replace('db_name', $_SESSION['db_name'], $filecontent);
$filecontent = str_replace('db_host', $_SESSION['db_host'], $filecontent);
$filecontent = str_replace('db_user', $_SESSION['db_user'], $filecontent);
$filecontent = str_replace('db_password', $_SESSION['db_password'], $filecontent);
file_put_contents("connect.php", $filecontent);
//Insert new admin users
$conn = new PDO("mysql:host=".$_SESSION['db_host'].";dbname=".$_SESSION['db_name'], $_SESSION['db_user'], $_SESSION['db_password']);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = 'INSERT INTO users ( username, password, role, join_date, birth_date ) VALUES ( :username, :password, :role, :join_date, :birth_date )';
$st = $conn->prepare ( $sql );
$st->bindValue( ":username", $admin_user, PDO::PARAM_STR );
$st->bindValue( ":password", $admin_password, PDO::PARAM_STR );
$st->bindValue( ":role", 'admin', PDO::PARAM_STR );
$st->bindValue( ":join_date", date('Y-m-d'), PDO::PARAM_STR );
$st->bindValue( ":birth_date", date('Y-m-d'), PDO::PARAM_STR );
$st->execute();
//
if(is_https()){
$sql = "UPDATE settings SET value = :value WHERE name = :name LIMIT 1";
$st = $conn->prepare($sql);
$st->bindValue(":name", 'use_https', PDO::PARAM_STR);
$st->bindValue(":value", 1, PDO::PARAM_STR);
$st->execute();
}
$conn = null;
session_unset();
// Double check
if(file_exists('cloudarcade.zip')){
unlink('cloudarcade.zip');
}
if(file_exists('unpack.php')){
unlink('unpack.php');
}
if(file_exists('db/tables.sql')){
unlink('db/tables.sql');
}
//
?>
Error. Unsupported characters detected.