MySQLI 连接,没有 INSERT/SELECT,没有错误
MySQLI Connects, Doesn't INSERT/SELECT, No Errors
我有一个 XAMPP 运行 的本地实例,那里一切正常。但是当将应用程序移植到 HostGator 时,我能够连接到数据库,但无法插入其中或 SELECT.
我创建了一个拥有所有数据库权限的新用户,并将该用户附加到相关数据库。下面是我的代码(这里显然没有显示凭据):
dbconnect.php
$dbhost = 'localhost';
$dbuser = '(myuser)';
$dbpass = '(my pass)';
$db = '(mydb)';
$conn = mysqli_connect($dbhost,$dbuser, $dbpass,$db);
helper.php(从 registration.php 调用)
static function validateRegistration(){
if (isset($_POST)) {
//Gather And Sanitize User Input
@$username = sanitize($_POST["username"]);
@$firstname = sanitize($_POST["firstname"]);
@$lastname = sanitize($_POST["lastname"]);
@$email = sanitize($_POST["email"]);
@$email = (filter_var($email, FILTER_SANITIZE_EMAIL));
@$cellphone = sanitize($_POST["cellphone"]);
@$university = sanitize($_POST["university"]);
@$address = sanitize($_POST["address"]);
@$city = sanitize($_POST["city"]);
@$postcode = sanitize($_POST["postcode"]);
@$state = sanitize($_POST["state"]);
@$username = sanitize($_POST["username"]);
@$password = sanitize($_POST["password"]);
@$confirm = sanitize($_POST["confirm"]);
@$paymentmethod = sanitize($_POST["paymentmethod"]);
@$PaymentID = sanitize($_POST["PaymentID"]);
//Collect errors, if any are present
$errors = array();
if (strlen($firstname) <= 1 || strlen($firstname) > 32){
array_push($errors, 'First Name must be between 1 and 32 characters!');
}else{
}
if (strlen($lastname) <= 1 || strlen($lastname) > 32){
array_push($errors, 'Last Name must be between 1 and 32 characters!');
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
array_push($errors, 'E-Mail Address does not appear to be valid!');
}
if (strlen($cellphone) <= 2 || strlen($cellphone) >= 32) {
array_push($errors, 'Cell phone must be between 3 and 32 characters!');
}
if (strlen($address) <= 1 || strlen($address) >= 128) {
array_push($errors, 'Address 1 must be between 3 and 128 characters!');
}
if (strlen($city) <= 1 || strlen($city) >= 128) {
array_push($errors, 'City must be between 2 and 128 characters!');
}
if (strlen($postcode) <= 1 || strlen($postcode) >= 10) {
array_push($errors, 'Postcode must be between 2 and 10 characters!');
}
if (strlen($password) <= 3 || strlen($password) >= 20) {
array_push($errors, 'Password must be between 2 and 128 characters!');
}
if ($password != $confirm) {
array_push($errors, 'Your passwords do not match!');
}
}//END POST
//***********Check for available Username and Email***************//
include('dbconnect.php');
$registration = new RegistrationHelper();
$sql = "SELECT Username FROM User WHERE Username = '" . $username . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
array_push($errors, 'Username is already taken');
}
$sql = "SELECT Email FROM User WHERE Email = '" . $email . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
array_push($errors, 'Email is already taken.');
}
if(count($errors) > 0){
return $errors;
}else{
include('dbconnect.php');
//***************If we get this far, Register User - Will need admin approval***************
$saltedPass = base64_encode($registration->salt . $password . $registration->salt);
$insertSQL = "INSERT INTO User (Username, FirstName, LastName, Email, Cell, Password, Active, PaymentGateway, PaymentGatewayID)
Values ('" . $username . "', '" . $firstname . "', '" . $lastname . "', '" . $email . "', '" . $cellphone . "', '" . $saltedPass . "', 0, '" . $paymentmethod . "', '" . $PaymentID . "')";
$conn->query($insertSQL);
if ($conn->query($insertSQL) === TRUE) {
echo "New record created successfully";
$conn->close();
}
}
}//END validateRegistration()
代码在此函数中运行,但在 2 个 SELECT 语句中失败,
$conn->query($sql);
$conn->query($insertSQL);
也没有通过这个:
if ($conn->query($insertSQL) === TRUE) {
echo "Record created successfully";
$conn->close();
}
我已经联系 HostGator 寻求他们的帮助,但他们不知道。用户拥有所有默认(完全)权限。代码没有改变,最终在 XAMPP.
本地运行
显然我的 MySQL 本地实例不区分大小写,但在 HostGator 实例上,它区分大小写。通过匹配数据库表的大小写,我能够解决问题。
我有一个 XAMPP 运行 的本地实例,那里一切正常。但是当将应用程序移植到 HostGator 时,我能够连接到数据库,但无法插入其中或 SELECT.
我创建了一个拥有所有数据库权限的新用户,并将该用户附加到相关数据库。下面是我的代码(这里显然没有显示凭据):
dbconnect.php
$dbhost = 'localhost';
$dbuser = '(myuser)';
$dbpass = '(my pass)';
$db = '(mydb)';
$conn = mysqli_connect($dbhost,$dbuser, $dbpass,$db);
helper.php(从 registration.php 调用)
static function validateRegistration(){
if (isset($_POST)) {
//Gather And Sanitize User Input
@$username = sanitize($_POST["username"]);
@$firstname = sanitize($_POST["firstname"]);
@$lastname = sanitize($_POST["lastname"]);
@$email = sanitize($_POST["email"]);
@$email = (filter_var($email, FILTER_SANITIZE_EMAIL));
@$cellphone = sanitize($_POST["cellphone"]);
@$university = sanitize($_POST["university"]);
@$address = sanitize($_POST["address"]);
@$city = sanitize($_POST["city"]);
@$postcode = sanitize($_POST["postcode"]);
@$state = sanitize($_POST["state"]);
@$username = sanitize($_POST["username"]);
@$password = sanitize($_POST["password"]);
@$confirm = sanitize($_POST["confirm"]);
@$paymentmethod = sanitize($_POST["paymentmethod"]);
@$PaymentID = sanitize($_POST["PaymentID"]);
//Collect errors, if any are present
$errors = array();
if (strlen($firstname) <= 1 || strlen($firstname) > 32){
array_push($errors, 'First Name must be between 1 and 32 characters!');
}else{
}
if (strlen($lastname) <= 1 || strlen($lastname) > 32){
array_push($errors, 'Last Name must be between 1 and 32 characters!');
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
array_push($errors, 'E-Mail Address does not appear to be valid!');
}
if (strlen($cellphone) <= 2 || strlen($cellphone) >= 32) {
array_push($errors, 'Cell phone must be between 3 and 32 characters!');
}
if (strlen($address) <= 1 || strlen($address) >= 128) {
array_push($errors, 'Address 1 must be between 3 and 128 characters!');
}
if (strlen($city) <= 1 || strlen($city) >= 128) {
array_push($errors, 'City must be between 2 and 128 characters!');
}
if (strlen($postcode) <= 1 || strlen($postcode) >= 10) {
array_push($errors, 'Postcode must be between 2 and 10 characters!');
}
if (strlen($password) <= 3 || strlen($password) >= 20) {
array_push($errors, 'Password must be between 2 and 128 characters!');
}
if ($password != $confirm) {
array_push($errors, 'Your passwords do not match!');
}
}//END POST
//***********Check for available Username and Email***************//
include('dbconnect.php');
$registration = new RegistrationHelper();
$sql = "SELECT Username FROM User WHERE Username = '" . $username . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
array_push($errors, 'Username is already taken');
}
$sql = "SELECT Email FROM User WHERE Email = '" . $email . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
array_push($errors, 'Email is already taken.');
}
if(count($errors) > 0){
return $errors;
}else{
include('dbconnect.php');
//***************If we get this far, Register User - Will need admin approval***************
$saltedPass = base64_encode($registration->salt . $password . $registration->salt);
$insertSQL = "INSERT INTO User (Username, FirstName, LastName, Email, Cell, Password, Active, PaymentGateway, PaymentGatewayID)
Values ('" . $username . "', '" . $firstname . "', '" . $lastname . "', '" . $email . "', '" . $cellphone . "', '" . $saltedPass . "', 0, '" . $paymentmethod . "', '" . $PaymentID . "')";
$conn->query($insertSQL);
if ($conn->query($insertSQL) === TRUE) {
echo "New record created successfully";
$conn->close();
}
}
}//END validateRegistration()
代码在此函数中运行,但在 2 个 SELECT 语句中失败,
$conn->query($sql);
$conn->query($insertSQL);
也没有通过这个:
if ($conn->query($insertSQL) === TRUE) {
echo "Record created successfully";
$conn->close();
}
我已经联系 HostGator 寻求他们的帮助,但他们不知道。用户拥有所有默认(完全)权限。代码没有改变,最终在 XAMPP.
本地运行显然我的 MySQL 本地实例不区分大小写,但在 HostGator 实例上,它区分大小写。通过匹配数据库表的大小写,我能够解决问题。