Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 上载前无法显示图像_Javascript_Php_Jquery_Image Uploading_Preview - Fatal编程技术网

Javascript 上载前无法显示图像

Javascript 上载前无法显示图像,javascript,php,jquery,image-uploading,preview,Javascript,Php,Jquery,Image Uploading,Preview,这是我的问题,当我尝试将图像更改为我的第二个数据时,它没有更改,但当我尝试第一个数据时,它正在更改,我不知道它无法处理第二个数据的原因。有人能帮我吗 这是我的表格,图像和文件在其中 更新 这是图片,id为42的新闻,当我改变图像时,图像没有改变,但id为40的新闻正在改变 这是我的全部代码。 $stmt = mysqli_prepare($con, "SELECT * FROM news ORDER BY news_id"); mysqli_stmt_execute($stmt);

这是我的问题,当我尝试将图像更改为我的第二个数据时,它没有更改,但当我尝试第一个数据时,它正在更改,我不知道它无法处理第二个数据的原因。有人能帮我吗

这是我的表格,图像和文件在其中

更新 这是图片,id为42的新闻,当我改变图像时,图像没有改变,但id为40的新闻正在改变

这是我的全部代码。
  $stmt = mysqli_prepare($con, "SELECT * FROM news ORDER BY news_id");
  mysqli_stmt_execute($stmt);
  $result = mysqli_stmt_get_result($stmt);
  while($row = mysqli_fetch_array($result)){
  ?>
   <tr>
  <td><?php echo $row['news_id']; ?></td>
  <td><?php echo $row['news_title']; ?></td>
  <td><?php echo $row['news_date']; ?></td>
  <td><?php echo $row['news_content']; ?></td>
  <td><img style="height:150px; width:200px;" src="<?php echo $row['news_image']; ?>"  ></td>
  <td>

  <button class="btn btn-info" data-toggle="modal" data-target="#newsedit<?php echo $row['news_id'];?>"><span class="glyphicon glyphicon-edit"></span>  Edit</button>
  <a class='btn btn-danger delete-object' data-toggle="modal" data-target="#newsdelete<?php echo $row['news_id'];?>"><span class="glyphicon glyphicon-remove"></span> Delete</a>

  <div class="modal fade" id="newsdelete<?php echo $row['news_id'];?>" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
              <div class="modal-content">
                    <div class="modal-body">
                       Are you sure you want to delete this?
                            </div>
     <div class="modal-footer">
      <a class='btn btn-danger left-margin' href="delete.php?newsid=<?php echo $row['news_id'];?>" >Yes</a>
    <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
          </div>
           </div>
          </div>
          </div>

     <div id="newsedit<?php echo $row['news_id'];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
             <div class="modal-dialog">
                 <div class="modal-content"> 
                        <div class="modal-header">
                                     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title" id="myModalLabel">Edit events</h4>
                                  </div>

                                 <div class="modal-body edit-content">
                                    <form method="POST" enctype="multipart/form-data" action ="edit2.php?newsid=<?=$row['news_id']?>">
                                          <div class="form-group">
                                            <label for="title">News Title</label>
                                            <input type="text" name="titles" class="form-control title" id="title" placeholder="News Title" value="<?php echo $row['news_title']; ?>">
                                          </div>

                                          <div class="form-group">
                                             <label for="date">Date</label>
                                             <input type="text" name="dates" class="form-control date" id="date" placeholder="Date" value="<?php echo $row['news_date']; ?>"s>
                                         </div>

                                         <div class="form-group">
                                            <label for="content">News Content</label>
                                            <textarea class="form-control content" name="contents" rows="5" id="content"><?php echo $row['news_content']; ?></textarea>
                                         </div>


                                         <img id="blah" name="newsimages" src="<?php echo $row['news_image']; ?>" width="200px" height="140px"/>
                                            <input id="image" name="image" class="fileupload" type="file" accept="image/*"/>

                                 </div>

                               <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <button type="submit" class='btn btn-info left-margin'>Yes</a>
                                  </form>
                            </div>
                              </div>
                        </div>
                   </div>


                </td>
            </tr>
        <?php
        }
        ?>
以下是上传前显示图像的js

<script type="text/javascript">
    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#blah').attr('src', e.target.result);
            }

            reader.readAsDataURL(input.files[0]);
        }
    }

    $("#image").change(function(){
        readURL(this);
    });
    </script>

使用类似以下内容:

函数readURLinput{ 如果输入.files&&input.files[0]{ var url=url.createObjectURLinput.files[0]; $input.SIBLINES'img'.attr'src',url; } } $.fileupload.changefunction{ 读懂这一点; };
使用类似以下内容:

函数readURLinput{ 如果输入.files&&input.files[0]{ var url=url.createObjectURLinput.files[0]; $input.SIBLINES'img'.attr'src',url; } } $.fileupload.changefunction{ 读懂这一点; };
只有第一个数据项正在更改,但第二个数据项未更改:@你在说什么数据输入?另外,在这里运行我的代码,您将看到它每次都有效。如果它在您的解决方案中不起作用,那么您没有提供相关代码。对不起,先生。我编辑了我的问题,你能再查一下吗,先生?谢谢,先生!你能解释一下下面的代码吗?哈哈。只有第一个数据条目在变化,但第二个数据条目没有变化@你在说什么数据输入?另外,在这里运行我的代码,您将看到它每次都有效。如果它在您的解决方案中不起作用,那么您没有提供相关代码。对不起,先生。我编辑了我的问题,你能再查一下吗,先生?谢谢,先生!你能解释一下下面的代码吗?哈哈。