gpt4 book ai didi

php - 无法将 PHP 更新发布到 MySQL

转载 作者:行者123 更新时间:2023-11-29 08:48:13 25 4
gpt4 key购买 nike

我有一个按钮,我试图到达哪里,如果我单击它,它会根据当前登录的用户( session )更新用户表中的“gorg”列,以提供者。每次我单击该按钮,我都会得到

Access denied for user 'root'@'localhost' (using password: NO)

这是 php 页面的顶部(顺便说一句,我 100% 肯定我的数据库连接信息是正确的)

<?php
session_start();
include('src/sql_handler.php'); //this is where my DB Connection info is located
include('src/facebook_handler_core.php');
if(isset($_POST['submitgiver'])) {
$query = "UPDATE users SET gorg='giver' WHERE email='".mysql_real_escape_string($_SESSION['email'])."'";
$result = mysql_query($query) or die(mysql_error());

}

{
if(isset($_SESSION['gorg'])=="Giver")
{
header('Location: picktreetype.php');
}
else if(isset($_SESSION['gorg'])=="Gatherer")
{
header('Location: gatherermap.php');
}

}

?>

现在是 html

<form method="post" action="<?php echo $PHP_SELF;?>">

<input type="submit" class="button orange" name="submitgiver" value="Giver">

</form>

更新:

这是 SQL_HANDLER

<?php


class MySQL_Con {

private $host = 'localhost',

$user = 'fruitfo1_admin',

$pass = 'password',

$db = 'fruitfo1_fruitforest',

$_CON;



function MySQL_Con() {

$this->_CON = mysql_connect($this->host, $this->user, $this->pass);

if(!$this->_CON)

die(mysql_error());

else {

$select_db = mysql_select_db($this->db);

if(!$select_db)

die('Error Connecting To Database'.mysql_error());

}

}

function End_Con() {

mysql_close($this->_CON);

}

}

?>

最佳答案

显然您的连接设置不包含密码。请发布sql_handler(密码已模糊)以便能够进一步调试。

如果您 100% 肯定这是正确的,正如您所说,您可以尝试将 sql 句柄显式传递给 mysql_query

另一个注意事项,mysql_* 已弃用,您确实应该考虑切换到 mysqliPDO

此外,对任何类型的 Web 应用程序使用 root 用户都是禁忌。

关于php - 无法将 PHP 更新发布到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12003574/

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