URL和mysqli中的问题

时间:2015-09-01 09:07:09

标签: php mysql

Hello stackoverflow人。我的脚本需要帮助。我已经获得了注册文件和索引文件,当我为索引文件创建案例时,当action被注册时,加载registration.php头,(index.php?action = register)我的注册脚本不起作用!我得到错误,找不到变量mysql(在register.inc.php文件中)。但是当URL正常时 - www.website.com/register.php那么一切都很好,你们知道这是什么问题吗?我该如何解决?

这是我的register.in.php文件开始:

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';

$error_msg = "";

if (isset($_POST['username'], $_POST['email'], $_POST['p'])) {
    // Sanitize and validate the data passed in
    $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $email = filter_var($email, FILTER_VALIDATE_EMAIL);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // Not a valid email
        $error_msg .= '<p class="error">The email address you entered is not valid</p>';
    }

    $password = filter_input(INPUT_POST, 'p', FILTER_SANITIZE_STRING);
    if (strlen($password) != 128) {
        // The hashed pwd should be 128 characters long.
        // If it's not, something really odd has happened
        $error_msg .= '<p class="error">Invalid password configuration.</p>';
    }

    $prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
    $stmt = $mysqli->prepare($prep_stmt);

错误是$ mysqli的最后一行。 $ mysql来自文件do_connect.php:

<?php
include_once 'psl-config.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);

请帮忙吗?

1 个答案:

答案 0 :(得分:1)

要跟踪错误,请使用分步方法。放

$prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
$stmt = $mysqli->prepare($prep_stmt);

正好在

之下
include_once 'db_connect.php';

手动将数据库中存在的任何电子邮件ID放入查询中。如果再次无法工作,则可能是包含文件的问题。如果它有效,那就先行一步。

$prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
$stmt = $mysqli->prepare($prep_stmt);

正好在

之下
include_once 'psl-config.php';

然后如果工作然后把它放在

之下
if (isset($_POST['username'], $_POST['email'], $_POST['p'])) {

等等。你最终会得到错误的原因。