Я пытаюсь создать систему регистрации, и недавно я добавил другие переменные в базу данных (rank, url, earnings, host_users, ftp_host, ftp_user, ftp_pass, client_id, plan_expire, beta_tester
)
Теперь мой код не создает пользователей в базе данных, но я не знаюwhy.
Код для functions.php для вставки пользователя в базу данных:
// register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password_1);//encrypt the password before saving in the database
if (isset($_POST['user_type'])) {
$user_type = e($_POST['user_type']);
$query = "INSERT INTO users (username, email, password, rank, url, earnings, host_users, ftp_host, ftp_user, ftp_pass, client_id, plan_expire, beta_tester)
VALUES('$username', '$email', '$password', '$rank', '$url', '$earnings, '$host_users', '$ftp_host', '$ftp_user', '$ftp_pass', '$client_id', '$plan_expire', '$beta_tester')";
mysqli_query($db, $query);
$_SESSION['success'] = "New user successfully created!!";
header('location: home.php');
}else{
$query = "INSERT INTO users (username, email, password, rank, url, earnings, host_users, ftp_host, ftp_user, ftp_pass, client_id, plan_expire, beta_tester)
VALUES('$username', '$email', '$password', '$rank', '$url', '$earnings, '$host_users', '$ftp_host', '$ftp_user', '$ftp_pass', '$client_id', '$plan_expire', '$beta_tester')";
mysqli_query($db, $query);
// get id of the created user
$logged_in_user_id = mysqli_insert_id($db);
$_SESSION['user'] = getUserById($logged_in_user_id); // put logged in user in session
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
}
}
Я использую это для create_user.php
<?php include('functions.php') ?>
<!DOCTYPE html>
<html>
<head>
<title>Registration system PHP and MySQL - Create user</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
.header {
background: #003366;
}
button[name=register_btn] {
background: #003366;
}
</style>
</head>
<body>
<div class="header">
<h2>Admin - create user</h2>
</div>
<form method="post" action="create_user.php">
<?php echo display_error(); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo $username; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo $email; ?>">
</div>
<div class="input-group">
<label>User type</label>
<select name="user_type" id="user_type" >
<option value=""></option>
<option value="admin">Admin</option>
<option value="user">User</option>
</select>
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn" name="register_btn"> + Create user</button>
</div>
</form>
</body>
</html>
В базе данных не создано ни одного пользователя...
register.php
<?php include('functions.php') ?>
<!DOCTYPE html>
<html>
<head>
<title>Registration system PHP and MySQL</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">
<h2>Register</h2>
</div>
<form method="post" action="adminregister.php">
<?php echo display_error(); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo $username; ?>">
</div>
<div class="input-group">
<label>URL</label>
<input type="url" name="url" value="<?php echo $url; ?>">
</div>
<div class="input-group">
<label>Rank (Admin/User)</label>
<input type="text" name="rank" value="<?php echo $rank; ?>">
</div>
<div class="input-group">
<label>Earnings</label>
<input type="text" name="earnings" value="<?php echo $earnings; ?>">
</div>
<div class="input-group">
<label>Host users</label>
<input type="text" name="host_users" value="<?php echo $host_users; ?>">
</div>
<div class="input-group">
<label>FTP host</label>
<input type="text" name="ftp_host" value="<?php echo $ftp_host; ?>">
</div>
<div class="input-group">
<label>FTP user</label>
<input type="text" name="ftp_user" value="<?php echo $ftp_user; ?>">
</div>
<div class="input-group">
<label>FTP pass</label>
<input type="text" name="ftp_pass" value="<?php echo $ftp_pass; ?>">
</div>
<div class="input-group">
<label>Client ID</label>
<input type="text" name="client_id" value="<?php echo $client_id; ?>">
</div>
<div class="input-group">
<label>Plan expire</label>
<input type="text" name="plan_expire" value="<?php echo $plan_expire; ?>">
</div>
<div class="input-group">
<label>beta_tester</label>
<input type="text" name="beta_tester" value="<?php echo $beta_tester; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo $email; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn" name="register_btn">Register</button>
</div>
<p>
Already a member? <a href="login.php">Sign in</a>
</p>
</form>
</body>
</html>