【发布时间】:2019-03-08 09:53:11
【问题描述】:
我通过ftp 将整个文件夹复制到网络应用程序,页面加载没有任何问题,我使用config/ 文件夹中的config.php 文件:
<?php
$host = '127.0.0.1';
$username = '-';
$password = '-';
$db_name = 'localdb';
//Establishes the connection
$link = mysqli_init();
mysqli_real_connect($link, $host, $username, $password, $db_name, 49187);
if (mysqli_connect_errno($link)) {
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
//Close the connection
mysqli_close($link);
?>
该链接有效,因为如果我转到index.php 页面时在连接位上填写了错误的详细信息,该页面甚至无法加载,我还尝试查看是否可以在此文件中创建一个表:
<?php
$host = '127.0.0.1';
$username = '-';
$password = '-';
$db_name = 'localdb';
//Establishes the connection
$link = mysqli_init();
mysqli_real_connect($link, $host, $username, $password, $db_name, 49187);
if (mysqli_connect_errno($link)) {
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
if (mysqli_query($link, '
CREATE TABLE test (
`Id` INT NOT NULL AUTO_INCREMENT ,
`test1` VARCHAR(200) NOT NULL ,
`test2` VARCHAR(50) NOT NULL ,
`test3` DOUBLE NOT NULL ,
PRIMARY KEY (`Id`)
);
')) {
printf("Table created\n");
}
//Close the connection
mysqli_close($link);
?>
这也有效,导航到左上角的index.php 时,您可以看到Table created。
我导出了我正在使用的数据库并将其导入到当前数据库中,这一切正常,连接不是问题。
所以在index.php页面上的登录代码是:
<?php
session_start();
if($_SESSION["loggedin"] == true){
header("location: dashboard.php");
}
require_once "config/config.php";
$email = $password = "";
$email_err = $password_err = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty(trim($_POST["email"]))){
$email_err = "Please enter your email address.";
} else{
$email = trim($_POST["email"]);
}
if(empty(trim($_POST["password"]))){
$password_err = "Please enter your password.";
} else{
$password = trim($_POST["password"]);
}
if(empty($email_err) && empty($password_err)){
$sql = "SELECT id, email, password FROM members WHERE email = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "s", $param_email);
$param_email = $email;
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
// Bind result variables
mysqli_stmt_bind_result($stmt, $id, $email, $hashed_password);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashed_password)){
session_start();
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["email"] = $email;
header("location: dashboard.php");
} else{
$password_err = "The password you entered was not valid.";
}
}
} else{
$email_err = "No account found with that email.";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($link);
}
?>
为什么我这么困惑是因为除了
$host = '127.0.0.1';
$username = '-';
$password = '-';
$db_name = 'localdb';
这些细节已经改变。
【问题讨论】:
-
updating rows,但是在哪里是更新查询? -
对不起
updating rows我的意思是SELECTUPDATEINSERT等,它在我的旧网站上运行,没有任何问题,但是由于我出于某种原因从我的旧分贝到新分贝不起作用。在我的config.php文件中创建表时,它确实创建了一个新表,我还创建了行,删除它们没有任何问题,但members和servers表不起作用。