gpt4 book ai didi

php - mysql_query() : Access denied for user '' @'localhost'

转载 作者:行者123 更新时间:2023-11-29 04:18:17 25 4
gpt4 key购买 nike

<分区>

我看到有很多类似的问题,但我找不到任何人有类似的代码。

脚本将文件上传到服务器,但我还想插入有关已上传文件的数据。文件按应有的方式上传,没有错误,但 phpmyadmin 中的表仍为空。

error_log 中的错误:

PHP Warning:  mysql_query(): Access denied for user ''@'localhost' (using password: NO) in *path*/upload.php on line 65
PHP Warning: mysql_query(): A link to the server could not be established in *path*/upload.php on line 65

当我在网站上得到输出“通过 UNIX 套接字 127.0.0.1 通过 TCP/IP 的本地主机”而不是 mysql 警告/错误时,连接似乎正常工作。

连接脚本(uploadconnect.php):

<?php
$mysqli = new mysqli("localhost", "*username*", "*password*", "*database*");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";

$mysqli = new mysqli("127.0.0.1", "*username*", "*password*", "*database*", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

echo $mysqli->host_info . "\n";
?>

上传PHP脚本:

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit" name="btn-upload">upload</button>
</form>

<?php
include_once 'uploadconnect.php';
if(isset($_POST['btn-upload']))
{

$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";

$new_size = $file_size/1024;

$new_file_name = strtolower($file);

$final_file=str_replace(' ','-',$new_file_name);

if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO uploadedfiles(file,type,size) VALUES('$final_file','$file_type','$new_size')";
mysql_query($sql); #<--- LINE 65
?>
<script>
alert('successfully uploaded');
window.location.href='upload.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='upload.php?fail';
</script>
<?php
}
}
?>

错误似乎发生在“mysql_query($sql);”在上传文件的第 65 行。

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