0

This is my update.php file I am unable to update my data in database. I have also attached a error screenshot which I have faced at the time of updating the data.

this is the image displaying error message

I not able to fetch data perfectly on update.php page.

update.php

<?php
include('config.php');

$update_record=$_GET['update'];
$query="select * from form_sql where id='$update_record' ";
$run=mysqli_query($conn, $query);

while ($row=mysqli_fetch_array($run))
{
    $fname=$row['fname'];
    $lname=$row['lname'];
    $country=$row['country'];
    $subject=$row['subject'];
    $hobbies=$row['hobbies'];
    $gender=$row['gender'];


}
?>



<!DOCTYPE html>
<html>
<head>

</head>
<body>

<h3>Update Form</h3>

<div class="container">
  <form name="sql" action="update.php" method="GET">
    <label for="fname">First Name</label>
    <input type="text" name="fname" placeholder="Your name.." value="<?php echo $fname; ?>" required>

    <label for="lname">Last Name</label>
    <input type="text" name="lname" placeholder="Your last name.." value="<?php echo $lname; ?>" required>


    <label for="country" name="country" value="<?php echo $country; ?>" >Country</label>
    <select id="country" name="country">
      <option value="australia">Australia</option>
      <option value="canada">Canada</option>
      <option value="usa">USA</option>
    </select>

    <label for="subject">Comments</label>
    <textarea id="subject" name="subject" placeholder="Write something.." style="height:200px" value="<?php echo $subject; ?>" required></textarea>

<br>    
<br>    
    <label for="Hobbies">Hobbies</label>
<br>    
    <input type="checkbox" name="hobbies[]" value="playing">Playing<br>
    <input type="checkbox" name="hobbies[]" value="music">Music<br>
    <input type="checkbox" name="hobbies[]" value="dane">Dancing<br>
    <br>

    <label for="gender">Gender</label>
    <br>    
    <input type="radio" name="gender" value="Male">Male
    <input type="radio" name="gender" value="Female">Female<br>


    <input type="submit" value="Update" name="update">



  </form>
</div>

</body>
</html>

view.php

This is my view.php file I am unable to update my data in dataabse.

<?php
include('config.php');

$result = mysqli_query($conn, "SELECT * FROM form_sql");

?>

<html>
<head>
</head>
<body>

<?php

echo "<table width='100%' border='1'>
<tr>
<td><strong>First Name</strong></td>
<td><strong>Last Name</strong></td>
<td><strong>Country</strong></td>
<td><strong>Comments</strong></td>
<td><strong>Hobbies</strong></td>
<td><strong>Gender</strong></td>
<td><strong>Edit</strong></td>
<td><strong>Delete</strong></td>

</tr>";

while($row = mysqli_fetch_array($result))
  {

echo "<tr>";
echo "<td>".$row['fname'] ."</td>";
echo "<td>".$row['lname'] ."</td>";
echo "<td>".$row['country']."</td>";
echo "<td>".$row['subject']."</td>";
echo "<td>".$row['hobbies']."</td>";
echo "<td>".$row['gender']."</td>";


echo "<td><a href="update.php?id=$row[Id]">Update</a></td>";



echo "<td><a href=\"delete.php?id=$row[Id]\">Delete</a></td>";  



echo "</tr>";
  }
echo "</table>";

?>

</body>
</html>
Kumar
  • 35
  • 5
  • 1
    Where are you actually updating anything? – aynber Dec 12 '17 at 14:50
  • Where is your update code? – Amit Gupta Dec 12 '17 at 15:03
  • 1
    Well you have the error "undefined index update on line 4" and in your php you do a "$_GET['update']" but in your ERROR URL you only have "id=6"...so you need to make a "$_GET['id']" to get the "6" or change your "id" in URL by "update=/the data you want/". With this you should solve your screenshot error – Mickaël Leger Dec 12 '17 at 15:04
  • I edited my question firstly I want to fetch data from database for update.php file. – Kumar Dec 12 '17 at 15:06
  • 1
    @Kumar have you tried what Mickael Leger suggested? Also, your code is vulnerable to [SQL injection](https://en.wikipedia.org/wiki/SQL_injection), make sure you use prepared statement https://secure.php.net/manual/en/mysqli.prepare.php – zstate Dec 12 '17 at 15:36

0 Answers0