简体   繁体   中英

PHP can't find mySQL database

I've got the following markup and 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. 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 $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中为此数据库专门创建一个拥有所有权利的新用户,为我解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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