0

我的网站上注册表单的 PHP 代码有问题。提交表单时,某些代码不会执行。

if ($fnameError = "" && $emailError = "" && $userError = "" && $passError = "" && $cpassError = "" && $tickError = "") {
    $con = mysqli_connect("localhost","root","","login")or die("Can't connect to database");

    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $name = $_POST['fname'];
    $email = $_POST['email'];

    $pwd = crypt('$pass', '$user');
    $pwd = md5($pwd);
    $tblname = "users";
    $flp="INSERT INTO $tblname (Name, Username, Password, Email Address)
        VALUES
        ('$name','$user','$pass','$email')";
    $res = mysqli_query($con, $flp)or die("Can't insert to table");
    if ($res) {
        $complete = "Registered successfully please log in to continue";
    } else {
        echo "error";
    }       
}

一切正常,直到到达开始 $flp="INSERT INTO...

任何人都可以帮助我调试此代码,另外,请不要链接到我希望能够使用此代码的已经编写的代码。

编辑:

我更改了一行以故意导致错误,因此我知道 PHP 正在读取该行,并且它确实给了我以 $res=mysqli_... 开头的行的语法错误

“解析错误:语法错误,第 85 行 C:\XamppNew\htdocs\site\regusr.php 中的意外 '$res' (T_VARIABLE)”

我删除了插入行末尾的分号只是为了得到错误。

编辑:

我已经设法将问题隔离到 if 语句的开头。似乎该行并未将每个错误视为没有内容。但是,如果存在错误,它将显示在表单旁边的页面上,并且不会显示此类错误。

4

4 回答 4

0

尝试这个:

<?php

//if ($fnameError = "" && $emailError = "" && $userError = "" && $passError = "" && $cpassError = "" && $tickError = "")
//{
    // Connect to DB
    $mysqli = new mysqli("localhost", "root", "", "login");
    if ($mysqli->connect_errno) {
        printf("Connect failed: %s\n", $mysqli->connect_error);
        exit();
    }

    // Parse Input
    $user = $mysqli->real_escape_string($_POST['user']);
    $pass = $mysqli->real_escape_string($_POST['pass']);
    $pwd = md5(crypt('$pass', '$user'));
    $name = $mysqli->real_escape_string($_POST['fname']);
    $email = $mysqli->real_escape_string($_POST['email']);

    // Insert Record
    if ($mysqli->query("INSERT INTO users (`Name`, `Username`, `Password`, `Email Address`) VALUES ('$name', '$user', '$pwd', '$email')")) {
        printf ("New user has id %d.\n", $mysqli->insert_id);
    } else {
        printf("Failed to insert row: %s\n", $mysqli->error);
    }

    // Close DB Connection
    $mysqli->close();
//}

?>
于 2013-11-01T09:56:00.367 回答
0

试试这个........... $flp="INSERT INTO $tblname (Name, Username, Password, EmailAddress) VALUES ('".$name."','".$user."',' ".$pass."','".$email."')";

于 2013-11-01T09:43:23.890 回答
0

您需要引用(带反引号)您的列名Email Address,因为它有一个空格。

于 2013-11-01T09:26:51.953 回答
0

在字段中使用反引号,Email Address因为它有空间。

$flp="INSERT INTO $tblname (`Name`, `Username`, `Password`, `Email Address`)
于 2013-11-01T09:28:09.127 回答