我有一个正在运行的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){
回显“记录创建成功”;
$ conn-> close();
}
我已经联系HostGator获取他们的帮助,他们没有任何想法。用户具有所有默认(完全)权限。该代码未更改,并且可以在XAMPP上最终在本地工作。
答案 0 :(得分:0)
显然我的MySQL本地实例不区分大小写,但是在HostGator实例上,它区分大小写。通过匹配数据库表的大小写,我能够解决此问题。