Can't connect to GoDaddy mysqli database via PHP script

☆樱花仙子☆ 提交于 2020-12-26 12:53:17

问题


Been trying for ages but just can't get my php script to connect to a mysqli database on my GoDaddy server. I've checked the username, password, database name countless times. Here's the script. Grateful for any advice.

$con = mysqli_connect("localhost","username","password","Villa1234");
$sql = "SELECT * FROM Prospects WHERE email = '$loginEmail'";
if ($result = mysqli_query($con,$sql)) {
    $rows = mysqli_num_rows($result);
    if ($rows == 1) {
        $firstRow = mysqli_fetch_assoc($result);
        $status = $firstRow['status'];
        $access = $firstRow['access'];
        $pid = $firstRow['prospect_ID'];
        if ($status == "Pending") {
            $loginResult = "pending";
        } else if ($access == "locked") {
            $loginResult = "locked";    
        } else {
            $storedPassword = $firstRow['password'];
            if ($storedPassword === $password) {
                $loginResult = "success";
                $firstName = $firstRow['firstname'];
                $_SESSION['loginEmail'] = $loginEmail;
            } else {
                $loginResult = "incorrect password";
            };
        };
    } else if ($rows == 0) {
        $loginResult = "email not registered";
    };  
};
mysqli_free_result($result);
mysqli_close($con); 

回答1:


You could try this: (Even if it doesn't work, it will atleast display the error you are facing)

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
error_reporting(E_ALL);
$con = new mysqli("localhost","username","password","Villa1234");

$sql = "SELECT * FROM Prospects WHERE email = ?";
$stmt = $con->prepare($sql);
$stmt->bid_param("s", $loginEmail);
$stmt->execute();
$result = $stmt->bind_result();
if($result->num_rows==1){
    while($firstRow=$result->fetch_assoc()){
        $status = $firstRow['status'];
        $access = $firstRow['access'];
        $pid = $firstRow['prospect_ID'];
        if ($status == "Pending") {
        $loginResult = "pending";
        }
        else if ($access == "locked") {
        $loginResult = "locked";    
        }
        else {
        $storedPassword = $firstRow['password'];
        if ($storedPassword === $password) {
            $loginResult = "success";
            $firstName = $firstRow['firstname'];
            $_SESSION['loginEmail'] = $loginEmail;
        } else {
            $loginResult = "incorrect password";
        }
        }
    }
}
else if ($rows == 0) {
    $loginResult = "email not registered";
}
?>


来源:https://stackoverflow.com/questions/40689520/cant-connect-to-godaddy-mysqli-database-via-php-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!