简体   繁体   English

将图像上传到文件夹并将图像名称上传到数据库

[英]Upload image to folder and image name to database

I know this is a long shot to ask but is their anyone that can show me how to upload an image to folder and image name to database?我知道这是一个很长的问题,但是他们的任何人都可以告诉我如何将图像上传到文件夹并将图像名称上传到数据库吗? I have looked and everything I find is mysql.我已经看过了,我发现的一切都是 mysql。 Mysql doesn't work for me I get many errors. Mysql 对我不起作用我有很多错误。 Here is a code that I have but it will not work for me这是我拥有的代码,但它对我不起作用

   <?php
  $hostname_connect= "localhost";
  $username_connect="torcdesi_barron7";
  $password_connect= "Tazmania9292";
  $database_connect="torcdesi_shirt";
   // Create connection
 $connect_solning =  mysqli_connect($hostname_connect, $username_connect, $password_connect, $database_connect) or trigger_error(mysqli_error(),E_USER_ERROR); 
     mysqli_select_db($connect_solning ,$database_connect) or die (mysqli_error($connect_solning)); 


 if($_POST)
 { 
 // $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.

 if ($_FILES["file"]["error"] > 0)
 {
 // if there is error in file uploading 
 echo "Return Code: " . $_FILES["file"]["error"] . "/>";

 }
 else
 {
  // check if file already exit in "images" folder.
  if (file_exists("images/" . $_FILES["file"]["name"]))
 {
 echo $_FILES["file"]["name"] . " already exists. ";
  }
 else
  {  //move_uploaded_file function will upload your image.  
   if(move_uploaded_file($_FILES["file"]   ["tmp_name"],"images/" . $_FILES["file"]["name"]))
     {
    // If file has uploaded successfully, store its name in data base
   $query_image = "insert into shirt_table (image)    values ('".$_FILES['file']['name']."', 'display','')";
     if(mysqli_query($query_image))
     {
   echo "Stored in: " . "images/" . $_FILES["file"]["name"];
   }
   else
    {
   echo 'File name not stored in database';
   }
   }
  }


   }
   }
   ?>

You have invalid query, you should use:您的查询无效,您应该使用:

INSERT INTO table (field1, field2, field3) VALUES (value1, value2, value3)

You use instead:你改用:

INSERT INTO table (field1) VALUES (value1, value2, value3)  

And empty quotes '' is a value too空引号''也是一个值

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

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