gpt4 book ai didi

php - 无法通过 PHP 连接到 MySQL 数据库

转载 作者:太空宇宙 更新时间:2023-11-03 10:54:14 25 4
gpt4 key购买 nike

<分区>

这可能只是某个地方的一个愚蠢错误,但我无法连接到 mysql。它已经困扰我好几天了!

我正在尝试为正在做的网上商店教程创建一个数据库。这是通过 Dreamweaver 和 cPanel 完成的。我试图从这段代码连接到我的 mysql 数据库:

-----connect_my_sql.php-----

 <?php
$db_host = "hostip";
$db_username = "build";
$db_pass = "*****";
$db_name = "myonlinestore";
$myConnection = mysqli_connect("$db_host","$db_username","$db_pass", "$db_name") or die ("could not connect to mysql".mysql_error());
?>

(密码和hostip已更改)其中username连接到数据库,psw是正确的。而且我没有从 .mysql_error() 得到任何错误

所有这些都是在我在 godaddy 上的主域的子文件夹中完成的。

已尝试创建一个管理页面,但我无法连接到我的数据库以使用我在 mysql 中创建的登录。女巫是以下代码:

<?php

session_start();
if (isset($_SESSION["manager"])) {
header("location: index.php");
exit();
}
?>
<?php

if (isset($_POST["username"]) && isset($_POST["password"])) {

$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters
// Connect to the MySQL database
include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); // query the person

$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $manager;
$_SESSION["password"] = $password;
header("location: index.php");
exit();
} else {
echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
exit();
}
}
?>

(我删除了代码中的所有样式)

我得到的只是信息不正确,但我已经在我的数据库中创建了一个管理表和用户。但是我无法登录。

我从这里得到的只是在我尝试连接时出现了一些问题。它必须是我的结果,因为 godaddy 看不到任何错误,或者我无法连接到那里的日志。

如果你能帮我解决这个问题,我将非常感激。

谢谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com