Php 在mysql中上载图像时给出空值

Php 在mysql中上载图像时给出空值,php,mysql,database,image,Php,Mysql,Database,Image,无法上载。上载图像时出现获取错误 echo "That's not an image."; else { if (!$insert = mysqli_query($db ,"INSERT INTO uploadimages (`Name`,`image`,`user_id` ) VALUES ('$image_name','$image',$user_id)")) echo "Problem uploading image."; else ==================

无法上载。上载图像时出现获取错误

    echo "That's not an image.";
else
{ 
if (!$insert = mysqli_query($db  ,"INSERT INTO uploadimages (`Name`,`image`,`user_id` )  VALUES ('$image_name','$image',$user_id)"))
echo "Problem uploading image.";
else

=================================================

     http://jsfiddle.net/amibhop/ja9fpo5b/
 <form id="form" action="" method="post" enctype="multipart/form-data" name="a">


                         <table width="65%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#EFEFEF">
     <input type= "file" name="image"><p>



       <td height="243" colspan=3 valign="top"> 
         <table width="100%" border=0 cellpadding="3">
           <tr>
             <td width="100%" align="left" class="desc"><span class="style5">
         <input type="button" name="Add" value="Add" onclick="addRow();"/>
         <input name="submit" type="button" id="submit" value="Delete" onclick="deleteRow1('tblSample1');" />
       </span></td>
           </tr>
           <tr>
             <td align="left" class="desc"> <table id = "tblSample1" >                    
                              </table>
                               <input type="hidden" name="tblid" /><input type="hidden" name="cid" value="<?php echo $_REQUEST['id']; ?>" /></td>
             </tr>
                  <tr bgcolor="white">
                    <td height="28" colspan="3" align="center"><div align="center">
                      <input type="submit" name="submit2" value="Save" class="button1" />
                      </div></td>
 </tr>
              </table></td></tr>
                 </table>

                   </form>
    </body>
   <?php
 //connect to database
 include('1.php');
 include("db.php");
 if(isset($_POST['submit2']))
 {
 $user_id=$_POST['cid'];
 // file properties
 $file = $_FILES["image"]["tmp_name"];
 if (!isset($file))
 echo "Please select an image.";
 else
 {
 $image =addslashes(file_get_contents($_FILES["image"]["tmp_name"]));
 $image_name = addslashes($_FILES["image"]["name"]);
 $image_size = getimagesize($_FILES["image"]["tmp_name"]);
 if ($image_size==FALSE)
 echo "That's not an image.";
 else
 {

 if (!$insert = mysqli_query($db  ,"INSERT INTO uploadimages (`Name`,`image`,`user_id` ) VALUES ('".$image_name."','".$image."','".$user_id.")"))
 echo "Problem uploading image.";
 else
 {
 $lastID= mysqli_query($db  ,'select * from uploadimages ORDER BY ID DESC LIMIT 1');
 $las=mysqli_fetch_array($lastID) ;
 $rea=$las['ID'];
 echo "Image uploaded <p> Your image:</p>echo <img src='uploadphoto1.php'?ID='$rea'>";
 }
 }
 }
 }
 ?>

 </html>
http://jsfiddle.net/amibhop/ja9fpo5b/


由于代码不完整,因此我将向您介绍该过程

收到请求后,获取文件名并将其存储在变量中。 将文件移动到文件夹中,然后将图像路径存储在数据库中

如果您遇到mysql错误,那么可能会出现多个问题。 1.表中有一个必填字段,您没有输入任何值。 2.列名不匹配或表名错误。 3.数据库连接也可能是一个问题

请使用
mysqli\u error($db)
查看问题的原因。首先指出错误,然后再解决它

您面临的问题可以通过这种方法解决

$imgname=$_FILES['image']['name'];
if($_FILES['image']['error']==0)
{
   $uploadFile=move_uploaded_file($_FILES['image']['tmp_name'],"/images/$imgname");
   if($uploadFile)
   {
    if (!$insert = mysqli_query($db  ,"INSERT INTO uploadimages 
           (`Name`,`image`,`user_id` ) VALUES 
            ('".$imgname."','".$imgname."','".$user_id.")"))
            echo "Problem uploading image.";
   else
   {
      $lastID= mysqli_query($db  ,'select * from uploadimages ORDER BY ID DESC LIMIT 1');
      $las=mysqli_fetch_array($lastID) ;
      $rea=$las['ID'];
      echo "Image uploaded <p> Your image:</p>echo <img src='uploadphoto1.php'?ID='$rea'>";
      }               
   }
$imgname=$\u文件['image']['name'];
如果($\u文件['image']['error']==0)
{
$uploadFile=移动上传的文件($UPLOADFILES['image']['tmp\u name'],“/images/$imgname”);
如果($uploadFile)
{
如果(!$insert=mysqli\u查询($db),则插入到上传的图像中
(`Name`、`image`、`user_id`)值
(“$imgname.”、“$imgname.”、“$user_id.”)等)
echo“上传图像时出现问题。”;
其他的
{
$lastID=mysqli_query($db,'select*from uploadimages ORDER BY ID DESC LIMIT 1');
$las=mysqli\u fetch\u数组($lastID);
$rea=$las['ID'];
echo“上传图像您的图像:

echo”; } }
我提供的链接可能重复您提供的链接只有html和css。您面临的是一个数据库和PHP问题。编辑您的问题并添加代码的相关部分以获得更好的帮助。您可以在js中看到这些内容。您可以想说多少次就说多少次,但我没有看到任何与PHP或sql相关的内容在链接中。如果可以,请在此处添加代码,或者尝试说服所有人在此处看到不可见的代码。我已经根据您的输入为您提供了解决方案。chk pl添加了几行代码