gpt4 book ai didi

PHP 找不到 mySQL 数据库

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

我有以下标记和 PHP。它用于画廊 - 上传和显示图像。我跟着this教程,但由于某种原因 mysqli_connect_db 找不到数据库。我错过了什么?

<?php
include('upload.php');
?>

<form action="index.php" method="POST" enctype="multipart/form-data">

Choose File: <input type="file" name="file">
Title: <input type="text" name="nam">
<input type="submit" name="submit">

</form>

和 PHP:

<?php

$con = mysqli_connect("localhost","Melvin","") or die ("could not connect to DB");
mysqli_select_db($con, "galerie") or die ("no database");

if(isset($_POST['submit'])){

$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$location = 'uploads/';
$target = 'uploads/' .$name;

if(move_uploaded_file($tmp_name,$location.$name)){

echo "file uploaded";

$nam = $_POST['nam'];
$query = mysqli_query($con , "INSERT INTO images(img_name,img_title)VALUES('".$target."','$nam')");

} else {

echo "file not uploaded";

}

}

$result = mysqli_query($con, "SELECT FROM images");
while($row = mysqli_fetch_array($result)){

echo "<img src=".$row['img_name']." &nbsp; class='addClass'>";

}

?>

最佳答案

此外,这缺少您选择的内容

$result = mysqli_query($con, "SELECT FROM images");

应该是(添加*):

$result = mysqli_query($con, "SELECT * FROM images");

关于PHP 找不到 mySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37687850/

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