简体   繁体   English

PHP无法找到MySQL数据库

[英]PHP can't find mySQL database

I've got the following markup and PHP. 我有以下标记和PHP。 It's for a gallery - to upload and display images. 用于画廊-上传和显示图像。 I followed through this tutorial, but for some reason the mysqli_connect_db can't find the DB. 我按照教程进行了学习,但是由于某些原因,mysqli_connect_db无法找到该数据库。 what am I missing? 我想念什么?

 <?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> 

and the PHP: 和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'>"; } ?> 

Also, this is missing what you are selecting 另外,这缺少您选择的内容

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

Should be (add *): 应为(添加*):

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

在mySQL中为此数据库专门创建一个拥有所有权利的新用户,为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM