PHP Ошибка: Первая страница Word Custom Custom Registration - на вашем сайте произошла критическая ошибка - PullRequest
0 голосов
/ 07 апреля 2020

Это мой первый форум для прессы на основе PHP, который я пытаюсь построить. Я слежу за онлайн-тутом, но получаю и ошибаюсь. Я знаю. Net довольно хорошо, но PHP для меня в новинку. Я никогда не видел эту ошибку раньше, и я не уверен, что моя ошибка в настоящее время

Сообщение об ошибке:

На вашем сайте произошла критическая ошибка. Узнайте больше о отладка в WordPress.

Я попытался включить режим отладки. Скорее всего, я сделал что-то не так.

PHP Код:

<?php
/* Template Name: WBG Registration */
global $wpdb;

if($_POST)
{
    $username = $wpdb->escape($_POST['txtUserName']);
    $email = $wpdb->escape($_POST['txtEmail']);
    $password = $wpdb->escape($_POST['txtPassword']);
    $confirmpassword = $wpdb->escape($_POST['txtConfirmPassword']);
    $recoveryquestion = $wpdb->escape($_POST['txtRecoveryQuestion']);
    $recoveryanswer = $wpdb->escape($_POST['txtRecoveryAnswer']);
    $error = array();

    if(strpos($username, ' ') !==FALSE)
    {
        $error['username_space'] = "Chat Handle can not contain spaces";
    }

    if(empty($username))
    {
        $error['username_empty'] = "Chat Handle required field";
    }

    if(username_exist($username))
    {
        $error['username_existt'] = "Chat Handle already exists";
    }

    if(!is_email($email))
    {
        $error['email_invalid'] = "Invalid Emaill Address";
    }

    if(email_exist($email))
    {
        $error['email_exist'] = "Email already being used";
    }

    if(empty($password))
    {
        $error['password_empty'] = "Password is required field";
    }


    if(count($error) == 0)
    {
        wp_create_user($username, $password, $email);
        echo "User Created";
        header("Location: http://www.whiteboxgaming.com");
        exit();
    }   
    else
    {
        print_r($error);
        header("Location: http://www.whiteboxgaming.com/registration");
    }   
}

?>

HTML:

<div style="width: 100%;">
<div style="width: 100%;background-color:#5BCBBC;">
    <!-- Banner -->
        <img src="https://whiteboxgaming.com/wp-content/uploads/2020/03/cropped-Header_WBG-3.png" alt="White Box Gaming Banner">
</div>
<div style="width:100%;background-color:#FFFFFF; font-size:40px; color:#C2C2C2;" align="left">
    <br><label>Registration</label><br><br>
    <form method="post">
        <div style="width: 100%;border: padding:60px; font-size:40px; color:#C2C2C2;" align="center">
            <div style="width: 100%; padding:25px;">
                <div style="width: 30%; height: 100px; float: left;" align="left">  
                    <label>Email</label><br>
                    <input type="text" name="txtEmail" id="txtEmail" placeholder="Email Address" style="font-size:20px; width: 90%;"/>
                </div>                              
                <div style="width: 30%; height: 100px; float: left;" align="left"> 
                    <label>Password</label><br>
                    <input type="password" name="txtPassword" id="txtPassword" placeholder="Enter Password" style="font-size:20px; width: 90%;"/>
                </div>
                <div style="width: 30%; height: 100px; float: left;" align="left"> 
                    <label>Chat Handle</label><br>
                    <input type="text" name="txtUserName" id="txtUserName" placeholder="User Name" style="font-size:20px; width: 90%;"/>
                </div>
            </div>
            <div style="width: 100%; padding:25px;">
                <div style="width: 30%; height: 100px; float: left;" align="left"> 
                    <label>Recovery Question</label><br>
                    <input type="text" name="txtRecoveryQuestion" id="txtRecoveryQuestion" placeholder="Recovery Question" style="font-size:20px; width: 90%;"/>
                </div>
                <div style="width: 30%; height: 100px; float: left;" align="left">  
                    <label>Recovery Answer</label><br>
                    <input type="text" name="txtRecoveryAnswer" id="txtResoveryAnswer" placeholder="Recovery Answer" style="font-size:20px; width: 90%;"/>
                </div>
                <div style="width: 30%; height: 100px; float: left;" align="left"></div>
            </div>
        </div>
        <div style="width: 100%; padding:25px;">
            <div style="width: 30%; height: 100px; float: left;" align="left">
                <!--<input type="submit" src="https://drive.google.com/uc?export=view&id=1OHKkPxRJgNZfORfVvUOOO4lMeeaTlthc" alt="Submit" width="100%" value="Create Account">-->
                <input type="image" src="https://drive.google.com/thumbnail?id=1W91IDBPLuVIRgk9lX_uGHkIWzJUhnE9l" alt="Create account" />
            </div>
            <div style="width: 30%; height: 100px; float: left;" align="left"></div>
            <div style="width: 30%; height: 100px; float: left;" align="left"></div>                
        </div>
    </form>
<br><br><br>
</div>

Не самый лучший код, но просто следуя Туту и ​​пытаясь адаптировать его к моим потребностям. Я ожидаю распечатать все данные в моем массиве при возникновении ошибки, иначе создайте учетную запись в моей базе данных Word Press. Любая помощь или видео будет здорово. Я новичок в словесной прессе и PHP. Я бы хотел исправить это.

Обновление: я сузил его до этих двух функций, которые я закомментировал в своем коде:

<?php
/* Template Name: WBG Registration */
global $wpdb;

if($_POST)
{
    $username = $wpdb->escape($_POST['txtUserName']);
    $email = $wpdb->escape($_POST['txtEmail']);
    $password = $wpdb->escape($_POST['txtPassword']);
    $confirmpassword = $wpdb->escape($_POST['txtConfirmPassword']);
    $recoveryquestion = $wpdb->escape($_POST['txtRecoveryQuestion']);
    $recoveryanswer = $wpdb->escape($_POST['txtRecoveryAnswer']);
    $error = array();


    if(strpos($username, ' ') !==FALSE)
    {
        $error['username_space'] = "Chat Handle can not contain spaces";
    }

    if(empty($username))
    {
        $error['username_empty'] = "Chat Handle required field";
    }

    /*
    if(username_exist($username))
    {
        $error['username_existt'] = "Chat Handle already exists";
    }*/

    if(!is_email($email))
    {
        $error['email_invalid'] = "Invalid Emaill Address";
    }

    /*
    if(email_exist($email))
    {
        $error['email_exist'] = "Email already being used";
    }*/

    if(empty($password))
    {
        $error['password_empty'] = "Password is required field";
    }

    if(count($error) == 0)
    {
        wp_create_user($username, $password, $email);
        header("Location: http://www.whiteboxgaming.com");
        exit();
    }   
    else
    {
        print_r($error);
        header("Location: http://www.whiteboxgaming.com/registration");
    }
}

?>

Я не уверен, как WordPress проверяет, если имя пользователя или адрес электронной почты уже существуют. Можно ли использовать функцию PHP?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...