Below are the codes for viewing the database and updating the database....
There are some errors which i m not understanding and i am confused...
Please help me out

Code for viewing the database is below.
[

<html>
<body>
<?php
$con = mysql_connect("localhost","root","manish");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("registerform", $con);

$result = mysql_query("SELECT * FROM users");

echo "<table border='1'>
<tr>
<th>id</th>
<th>Firstname</th>
<th>Gender</th>
<th>Birthyear</th>
<th>Update user</th>
<th>Delete User</th>


</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" .$row['id']. "</td>";
  echo "<td>" .$row['username']. "</td>";
  echo "<td>" .$row['gender']. "</td>";
  echo "<td>" .$row['birth_year']. "</td>";
  echo <a href=\"update2.php?id=".$row['id']."\" >Update</a>;
  echo "<td><a href=\"delete.php?id=".$row['id']."\">Delete</a></td>" ;
  echo "</tr>";
  }
  
echo "</table>";
mysql_close($con);
?>
    <center>
        <table>
                 <tr>
                <td align="center">
                     <ul>
                        <li><a href="update1.php">Updating Database</a></li>
                    </ul>
                </td>
            </tr>
        </table>
     </center>


</body>
</html>

now the code below is code for updating the database

<?php
    include "functions.php";
    if (!isset($_POST['submit']))
    {
    $query=" SELECT * FROM users WHERE id=$_GET[$id]";
    $result=mysql_query($query);
    $person=mysql_fetch_array($result);
    
    }
?>

        
        <center>
            <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>>
            <table border="0" style="width:250;text-align:left;border: 1px solid black;padding:2px; font-family:Verdana; font-size:12px; ">
            <tr>
                <td>
                    Username:
                </td>
                <td>
                    <input type="text" name="username" value="<?php echo $row['userrname'];?>" >
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>
                <td>
                    <input type="password" name="password" value="<?php echo $row['password'];?>">
                </td>
            </tr>
            <tr>
                <td>
                    Gender:
                </td>
                <td>
                    <select  name="gender">
                        <option value="<?php echo $row['male'];?>">Male</option>
                        <option value="<?php echo $row['female'];?>">Female</option>
                    </select>
                </td>
            </tr>
           <tr>
                <td>
                    Birth Year:
                </td>
                <td>
                    <select  name="birth_year">
                        <?php
                            $num=1978;
                            while($num <= 2008)
                            {
                                $num++;
                                echo "<option value=".$num.">".$num."</option> ";
                            }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
            <tr>
                <td colspan="2" align="center">
                    <input type-=hidden name=id value'<?php $_GET['id']; ?>"/>
                    <input type="submit" name="submit" value="Update">
                </td>
            </tr>
            </table>
            </form>
            </center>
<?php
if(isset($_POST['submit']))
{
          $query = "UPDATE users SET first_name = '$first_name',password = '$password', gender = '$gender', " .
            " birth_year = '$birth_year' WHERE ID = $_POST[id]";
            mysql_query($query) or die( mysql_error());
            
            echo "User has been modified";
            header("Location:index.php");
}
else{
    echo "Please fill the form ";
    header("Location:update2.php");
}
?>

On "Code for viewing the database" line 33 the echo is missing "" is missing

OLD

echo <a href=\"update2.php?id=".$row['id']."\" >Update</a>;

Changed

echo "<a href=\"update2.php?id=".$row['id']."\" >Update</a>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.