1

Here is my code for update table:

<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>

Below is the uprownews.php file. I'm facing one more issue in below code with not being able to update files (file & image) Note: Except files all data getting updated.

$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>";

Please guide me on how to do this.

Matt
  • 1,518
  • 4
  • 16
  • 30
Anita S
  • 21
  • 2
  • you need to give a id on the edit page and fetch it with `$_GET['id']` and use that in the query `$sql= " SELECT * FROM news WHERE id = " . $_GET['id'] ;` **p.s this is NOT safe you should learn to prevent SQL injections (https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) , i did it this way to easy explain it** – Raymond Nijland Sep 25 '18 at 11:07

2 Answers2

0

tag is used for file upload, it can't be set by any default value (How to set a value to a file input in HTML?)

But you can specify (for some reasons) that user has already uploaded data using this piece of code (not the best though):

echo "<input type="file" name="file" id='file1'><label for='file1'>".$row['File']."</label>"
Anton
  • 919
  • 7
  • 22
0

I have found everything right except one thing you are not concatenating in the right way replace the following line and then check

<td><a href='uprownews.php?id='.$row[id].''>Edit</a></td>

You have done concatenating in td tags I am just mentioning it. I assume you forgot to concatenate $row['id']

Rizwan
  • 79
  • 6