mysql — отправка формы, php, постоянно получаю сообщение об ошибке в массиве

Я работаю на форуме для школьного проекта (средняя школа), и у меня есть форма регистрации. Все работает, но когда я отправляю форму, я получаю ошибку установки, которая говорит: «Произошла ошибка». Я не получаю никаких ошибок MYSQL и мне интересно, что не так с моим кодом. Обратите внимание, что все должно работать, но по какой-то причине оно не отправляется в базу данных. Я знаю, что HTML хорош, поэтому я только отправляю php.

register.php

    <?php
//get required files
include 'inc/config.php';//get all variables to avoid errors
$firstname = ""; //first name of user
$lastname = ""; //last name of user
$username = ""; //username of user
$email = ""; //email of user
$city = ""; //current city
$password = ""; //password
$password2 = ""; //confirm password
$date = ""; //signup date
$error_array = array(); //holds all error messages
$ip = ""; //ip address of user
$allowed_cities = array("Toronto","Ottawa","Hamilton","London","Windsor","Kingston"); //holds all cities allowed
$profilepic = ""; //profile photo
$code = ""; //email token to verify account

//Profile Photo Settings
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation
$max_filesize = 9999999999; // Maximum filesize in BYTES - SET IN to a low number for small files
$upload_path = 'data/profilepictures/'; // The place the files will be uploaded to (currently a 'profile pictures' directory)if(isset($_POST['submit'])){

//First Name
$firstname = strip_tags($_POST['firstname']); //Remove html tags
$firstname = str_replace(' ', '', $firstname); //remove spaces
$firstname = ucfirst(strtolower($firstname)); //Uppercase first letter

//Last Name
$lastname  = strip_tags($_POST['lastname']); //Remove html tags
$lastname = str_replace(' ', '', $lastname); //remove spaces
$lastname = ucfirst(strtolower($lastname)); //Uppercase first letter

//Username
$username = strip_tags($_POST['username']); //Remove html tags
$username = str_replace(' ', '_', $username); //remove spaces and put a underscore
//Note: preg match for username done later

//Email
$email = strip_tags($_POST['email']); //Remove html tags
$email = str_replace(' ', '', $email); //remove spaces

//City
$city = strip_tags($_POST['city']); //Remove html tags
$city = str_replace(' ', '', $city); //remove spaces
$city = ucfirst(strtolower($city)); //Uppercase first letter

//Password and Confirm Password
$password = strip_tags($_POST['password']); //Remove html tags
$password2 = strip_tags($_POST['password2']); //Remove html tags

//Profile Picture
$profilepic = $_FILES['photo']['name']; // Get the name of the file (including file extension)
$ext = substr($profilepic, strpos($profilepic,'.'), strlen($profilepic)-1); // Get the extension from the profilepic

//Email Verification
$code=substr(md5(mt_rand()),0,15); //token to verify email//Date and IP Address
$date = date("Y-m-d"); //Current date
$ip = $_SERVER['REMOTE_ADDR']; //IP Address//Check submissions for errors

//Check Firstname
if(strlen($firstname) > 25 || strlen($firstname) < 2) {
array_push($error_array, "Your first name must be between 2 and 25 characters<br>");
}

//Check Lastname
if(strlen($lastname) > 25 || strlen($lastname) < 2){
array_push($error_array, "Your last name must be between 2 and 25 characters<br>");
}

//Check Username

$u_check = mysqli_query($con, "SELECT username FROM users WHERE username='$username'");

$num_rows = mysqli_num_rows($u_check);

if($num_rows > 0) {

array_push($error_array, "Username is taken<br>");

}

if(strlen($username) > 30 || strlen($username) < 3){
array($error_array, "Your username must be between 3 and 30 characters<br>");

}

if(preg_match('/^[a-z0-9]{6,10}$/', $username)) {
array_push($error_array, "Your username includes invalid characters<br>");
}

//Check Email

$e_check = mysqli_query($con, "SELECT email FROM users WHERE email='$email'");

$num_rows2 = mysqli_num_rows($e_check);

if($num_rows2 > 0){

array_push($error_array, "Email already in use<br>");}

$allowed_emails = array('student.tdsb.on.ca', 'delasalle.ca', 'ucc.on.ca');

$explodedEmail = explode('@', $email);
$domain = array_pop($explodedEmail);

if ( ! in_array($domain, $allowed_emails))
{
array_push($error_array, "Your student email is not allowed<br>");
}//Check City

if (!in_array($city, $allowed_cities)) {
array_push($error_array, "Our service is not available in your city<br>");
}

//Check Passwords

if($password != $password2) {
array_push($error_array,  "Your passwords do not match<br>");
}

if(strlen($password > 30 || strlen($password) < 5)) {
array_push($error_array, "Your password must be betwen 5 and 30 characters<br>");
}

if(preg_match('/[^A-Za-z0-9]/', $password)) {
array_push($error_array, "Your password can only contain english characters or numbers<br>");
}

//Check Profile Picture
if(!in_array($ext,$allowed_filetypes)){
array_push($error_array, "The file you attempted to upload is not allowed<br>");
}

if(filesize($_FILES['photo']['tmp_name']) > $max_filesize){
array_push($error_array, "The file you attempted to upload is too large<br>");

}

if(!is_writable($upload_path)){
array_push($error_array, "You cannot upload to the specified directory, please CHMOD it to 777<br>");
}

if(move_uploaded_file($_FILES['photo']['tmp_name'],$upload_path . $profilepic)){

}
else{
array_push ($error_array, "There was an error during the file upload. Please try again later<br>");
}

//Process Data

if(empty($error_array)) {
$password = md5($password); //Encrypt password before sending to database

$query = mysqli_query($con, "INSERT INTO users (firstname,lastname,email,username,password,signup_date,city,profilephoto,email_verified ) VALUES ('$firstname','$lastname','$email','$username','$password','$date','$profilepic','0') ");
array_push($error_array, "Your acccount has been created. Please check your inbox to verify your account<br>");

}

else{
array_push($error_array, "An error has occured. Please try again later<br>");
}}?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]