+2 votes
7 views

im coding a installation step by step page and that is where i am

index.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>EMI Installation</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../admin/assets/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../admin/assets/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../admin/ass/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../admin/dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="../admin/plugins/iCheck/square/blue.css">
    <link rel="shortcut icon" type="image/png" href="../admin/dist/img/favicon.png">

    <!--[if lt IE 9]>
    http://ift.tt/1LM8Erm
    http://ift.tt/1qIredN
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet" href="http://ift.tt/1kqTnVC">
</head>
<body class="hold-transition register-page" ><!--onload='myFunction()'-->



        EventManager Interface






        set('php_self', $_SERVER['PHP_SELF']);

                    echo $admin->output();
                    break;

                case "installation":


                    initTables();

                    $user = $_POST['adminuser'];
                    $mail = $_POST['adminmail'];
                    $hashed_pw = password_hash($_POST['adminpassword'], PASSWORD_BCRYPT);
                    createUser($user, $hashed_pw, $mail);

                    $installation = new Template('../admin/template/install_step_installation.tpl');
                    echo $installation->output();
                    break;

                default:
                    $db_install = new Template('../admin/template/install_step_db.tpl');
                    $db_install->set('php_self', $_SERVER['PHP_SELF']);

                    echo $db_install->output();

            }

        ?>


    <!-- /.form-box -->
</div>
<!-- /.register-box -->

<!-- jQuery 3 -->
http://../admin/assets/jquery/dist/jquery.min.js
<!-- Bootstrap 3.3.7 -->
http://../admin/assets/bootstrap/dist/js/bootstrap.min.js
<!-- iCheck -->
http://../admin/plugins/iCheck/icheck.min.js

    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });

</body>
</html>

dbconnect.php

<?php

include 'config.php';

$db = new mysqli($db_config['host'], $db_config['username'], $db_config['password'], '', $db_config['port']);

if ($db->connect_error) {
    echo "
Connection failed: " . $db->connect_error . "

";
}

function initTables() {
    global $db;
    global $db_config;
    global $db_tableprefix;
    $db->query("CREATE DATABASE IF NOT EXISTS " . $db_config['databasename']);
    $db->select_db($db_config['databasename']);
    $db->query("CREATE TABLE IF NOT EXISTS " . $db_tableprefix . "settings (property VARCHAR(99) NOT NULL, value VARCHAR(99) NOT NULL, PRIMARY KEY ( `property` ))");
    $db->query("CREATE TABLE IF NOT EXISTS " . $db_tableprefix . "users (username VARCHAR(99) NOT NULL, password VARCHAR(255) NOT NULL, email VARCHAR(99) NOT NULL, PRIMARY KEY ( `username` ))");
    $db->query("CREATE TABLE IF NOT EXISTS " . $db_tableprefix . "projects (project_name VARCHAR(255) NOT NULL, launch_date VARCHAR(255) NOT NULL, may_players VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, creator VARCHAR(255) NOT NULL, PRIMARY KEY ( `project_name` ));");
    $db->query("CREATE TABLE IF NOT EXISTS " . $db_tableprefix . "players (player_uuid VARCHAR(99) NOT NULL, player_name VARCHAR(15) NOT NULL, player_ipaddress VARCHAR(99), PRIMARY KEY ( `player_uuid` ))");
    //$db->query("CREATE TABLE IF NOT EXISTS " . $db_tableprefix . "link_player_projects (project_name VARCHAR(255) NOT NULL, player_uuid VARCHAR(99), FOREIGN KEY (`project_name`) REFERENCES projects(`project_name`), FOREIGN KEY (`player_uuid`) REFERENCES players(`player_uuid`)");
    $db->query("CREATE TABLE IF NOT EXISTS " . $db_tableprefix . "ranks (rank_name VARCHAR(15) NOT NULL, rank_shortcut VARCHAR(6) NOT NULL, rank_permission INT(2), PRIMARY KEY ( `rank_name` ))");

    $db->query("INSERT IGNORE INTO " . $db_tableprefix . "ranks VALUES ('Administrator', 'Admin', 99)");
    $db->query("INSERT IGNORE INTO " . $db_tableprefix . "ranks VALUES ('Moderator', 'Mod', 75)");
}

function createUser($user, $hashed_pw, $mail) {
    global $db;
    global $db_tableprefix;
    $db->query("INSERT IGNORE INTO " . $db_tableprefix . "users (username, password, email) VALUES (" . $user . ", " . $hashed_pw . ", " . $mail . ")");
    if ($db->errno) {
        echo "
Connection failed: " . $db->errno . "

";
    }
}

function getSetting($property) {
    global $db;
    global $db_tableprefix;
    $result = $db->prepare("SELECT value FROM " . $db_tableprefix . "settings WHERE property = " . $property . " LIMIT 1");
    while($row = $result->fetch_row()) {
        return $row['value'];
    }
}

function setSetting($property, $value) {
    global $db;
    global $db_tableprefix;
    $db->query("INSERT INTO " . $db_tableprefix . "settings (property, value) VALUES (" . $property . ", " . $value . ") ON DUPLICATE KEY UPDATE value =" . $value . " WHERE property = " . $property);
}

function checkUser($name, $password) {
    global $db;
    global $db_tableprefix;
    $result = $db->query("SELECT password FROM " . $db_tableprefix . "users WHERE username = " . $name . " OR LOWER(email) = LOWER(" . $name . ")");

    while($row = $result->fetch_assoc()) {
        if(password_verify($password, $row['password'])) {
            return true;
        } else {
            return false;
        }
    }
}


$db->close();
?>

my problem is it wont do the sql statements it once worked the tables got created but only the admin user won’t get inserted

anyone knows why it just wont work

im using a template engine to display the html code

by (2.4k points)   | 7 views

Please log in or register to answer this question.

Related questions

+2 votes
0 answers
+3 votes
1 answer
asked Jun 19 by athar (2.4k points) | 7 views
+2 votes
0 answers
+1 vote
0 answers
+2 votes
1 answer




Welcome to Meansflow - Where Developers and Students Learn, Share, & Build Careers, where you can ask questions and receive answers from other members of the community.
104 questions
74 answers
36 comments
92 users