Q:

Updating data in PHP

I am using editing file for updating data of mobile no, email details etc, but it is not updating , it shows the results of data so connection is working but no updating of data is there. code:
<?php

    include('header.php');
    $msg='';

     ?> 

<div class="page-cont1">                        
<!--heading starts-->

<?php

    session_start(); //starts the session
    if($_SESSION['user']){ //checks if user is logged in
    }
    else{
        header("location:index.php"); // redirects if user is not logged in
    }
    $user = $_SESSION['user']; //assigns user value
    $id_exists = false;
    ?>
    <body>
        <h2>Home Page</h2>
        <p>Hello <?php Print "$user"?>!</p> <!--Displays user's name-->
        <a href="logout.php">Click here to logout</a><br/><br/>
        <a href="home.php">Return to Home page</a>
        <h2 align="center">Currently Selected</h2>
        <table border="1px" width="100%">
            <tr>
                <th>Id</th>
                <th>E-Mail</th>
                <th>Mobile No</th>
                <th>Details</th>
                <th>Extra Information</th>

            </tr>
            <?php

                if(!empty($_GET['id']))
                {
                    $id = $_GET['id'];
                    $_SESSION['id'] = $id;
                    $id_exists = true;

                    $query = mysql_query("Select * from doctor Where id='$id'"); // SQL Query
                    $count = mysql_num_rows($query);
                    if($count > 0)
                    {
                        while($row = mysql_fetch_array($query))
                        {
                            Print "<tr>";
                                Print '<td align="center">'. $row['id'] . "</td>";
                                Print '<td align="center">'. $row['your_email'] . "</td>";
                                Print '<td align="center">'. $row['mobile_no'] . "</td>";
                                Print '<td align="center">'. $row['detail'] . "</td>";
                                Print '<td align="center">'. $row['info'] . "</td>";

                            Print "</tr>";
                        }
                    }
                    else
                    {
                        $id_exists = false;
                    }
                }
            ?>
        </table>
        <br/>
        <?php

        if($id_exists)
        {
        Print '
        <form action="edit.php" method="POST">
            Enter new E-Mail: <input type="text" name="your_email"/><br/>
            Enter new Mobile: <input type="text" name="mobile_no"/><br/>
            Enter new detail: <input type="text" name="detail"/><br/>
            Enter new Extra Information: <input type="text" name="info"/><br/>

            <input type="submit" value="Update List"/>
        </form>
        ';
        }
        else
        {
            Print '<h2 align="center">There is no data to be edited.</h2>';
        }
        ?>

<?php

    if($_SERVER['REQUEST_METHOD'] == "POST")
    {

        $field_email = mysql_real_escape_string($_POST['your_email']);
        $field_phone = mysql_real_escape_string($_POST['mobile_no']);
        $detail = mysql_real_escape_string($_POST['detail']);
        $field_message = mysql_real_escape_string($_POST['info']);

        mysql_query("UPDATE doctor SET your_email='$field_email', mobile_no='$field_phone', detail='$detail', info='$field_message' WHERE id='$id'") ;
        header("location: home.php");
    }
?>
<?php
    include('footer.php');
    $msg='';

     ?> 

</body>

More over header file includes the connect file, and one query form  is there problem lie in header file or problem in edit file.

A:

After receiving ans i studied my code in the ans i read about ID  so i noticed that in updating there is no ID reference so i changed my code now problem solved  my working code is:
<?php

    include('header.php');
    $msg='';

     ?> 

<div class="page-cont1">                        
<!--heading starts-->

<?php

    session_start(); //starts the session
    if($_SESSION['user']){ //checks if user is logged in
    }
    else{
        header("location:index.php"); // redirects if user is not logged in
    }
    $user = $_SESSION['user']; //assigns user value
    $id_exists = false;
    ?>
    <body>
        <h2>Home Page</h2>
        <p>Hello <?php Print "$user"?>!</p> <!--Displays user's name-->
        <a href="logout.php">Click here to logout</a><br/><br/>
        <a href="home.php">Return to Home page</a>
        <h2 align="center">Currently Selected</h2>
        <table border="1px" width="100%">
            <tr>
                <th>Id</th>
                <th>E-Mail</th>
                <th>Mobile No</th>
                <th>Details</th>
                <th>Extra Information</th>

            </tr>
            <?php

                if(!empty($_GET['id']))
                {
                    $id = $_GET['id'];
                    $_SESSION['id'] = $id;
                    $id_exists = true;

                    $query = mysql_query("Select * from doctor Where id='$id'"); // SQL Query
                    $count = mysql_num_rows($query);
                    if($count > 0)
                    {
                        while($row = mysql_fetch_array($query))
                        {
                            Print "<tr>";
                                Print '<td align="center">'. $row['id'] . "</td>";
                                Print '<td align="center">'. $row['your_email'] . "</td>";
                                Print '<td align="center">'. $row['mobile_no'] . "</td>";
                                Print '<td align="center">'. $row['detail'] . "</td>";
                                Print '<td align="center">'. $row['info'] . "</td>";

                            Print "</tr>";
                        }
                    }
                    else
                    {
                        $id_exists = false;
                    }
                }
            ?>
        </table>
        <br/>
        <?php

        if($id_exists)
        {
        Print '
        <form action="edit.php" method="POST">
            Enter new E-Mail: <input type="text" name="your_email"/><br/><br/>
            Enter new Mobile: <input type="text" name="mobile_no"/><br/><br/>
            Enter new detail: <textarea name="detail" rows="6" id="detail" style="width:200px;"></textarea><br/><br/>
            Enter new Extra Information: <textarea name="info" rows="4" id="info" style="width:200px;"></textarea><br/><br/>
            <input type="hidden" name="id" value="'.$id.'">

            <input type="submit" value="Update List"/>
        </form>
        ';
        }
        else
        {
            Print '<h2 align="center">There is no data to be edited.</h2>';
        }
        ?>

<?php

    if($_SERVER['REQUEST_METHOD'] == "POST")
    {

        $field_email = mysql_real_escape_string($_POST['your_email']);
        $field_phone = mysql_real_escape_string($_POST['mobile_no']);
        $detail = mysql_real_escape_string($_POST['detail']);
        $field_message = mysql_real_escape_string($_POST['info']);
        $id = $_SESSION['id'];
        mysql_query("UPDATE doctor SET your_email='$field_email', mobile_no='$field_phone', detail='$detail', info='$field_message' WHERE id='$id'") ;
        header("location: home.php");
    }
?>
<?php
    include('footer.php');
    $msg='';

     ?> 

</body>

