这是我的更新表代码:
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Date</th>
<th>Time</th>
<th>File</th>
<th>Image</th>
<th>Operation</th>
</tr>
</thead>
<?php
while($row = mysqli_fetch_assoc($data))
{
echo "<tr>
<td>".$row['Title']."</td>
<td>".$row['Description']."</td>
<td>".$row['Date']."</td>
<td>".$row['Time']."</td>
<td>".$row['File']."</td>
<td>".$row['Image']."</td>
<td><a href='uprownews.php?id=$row[id]'>Edit</a></td>
</tr>";
}
}
else {
echo "No Record Found";
}
?>
</table>
下面是uprownews.php文件。 我在下面的代码中面临另一个问题,无法更新文件(文件和图像)注意:除文件外,所有数据都将更新。
$conn=mysqli_connect($servername,$username,$password,$dbname);
$sql= " SELECT * FROM news ";
$records=mysqli_query($conn,$sql);
$row = mysqli_fetch_array($records);
echo "<form id=news_table action=uprownews.php method=post enctype=multipart/form-data>";
echo "<input type=hidden name=id value = '".$row['id']."'>";
echo "Title";
echo "<textarea name=title rows=2 cols=100> ".$row['Title']."</textarea><br><br>";
echo "Description ";
echo "<textarea name=description rows=20 cols=100>".$row['Description']."</textarea><br><br>";
echo "Date ";
echo "<input type=date name=date value = '".$row['Date']."'><br><br>";
echo "Time ";
echo "<input type=time name=time value = '".$row['Time']."'><br><br>";
echo "File ";
echo "<input type=file name=file>".$row['File']."<br><br>";
echo "Image ";
echo "<input type=file name=image>".$row['Image']."<br><br>";
echo "<input type=submit value=Update name=submit1 >";
echo "</form>";
请指导我如何做。
答案 0 :(得分:0)
标签用于文件上传,不能通过任何默认值(How to set a value to a file input in HTML?)设置
但是您可以(由于某些原因)使用这段代码来指定用户已经上传了数据(虽然不是最好的):
echo "<input type="file" name="file" id='file1'><label for='file1'>".$row['File']."</label>"
答案 1 :(得分:0)
我发现一切正常,除了一件事,即您没有以正确的方式连接起来,请替换以下行,然后检查
<td><a href='uprownews.php?id='.$row[id].''>Edit</a></td>
您已经完成了在td标签中的连接,我只是在提到它。我认为您忘记了串联$ row ['id']