after i key-in the form, the function change the whole column with the same value for example if i put first name JOHN it will update whole column with JOHN

            <?php

            session_start();
            require_once("connection.php");

            if (isset($_POST['edit'])) 
            {
              session_start();

                $s=mysqli_query($con,"UPDATE user SET first_name ='" . $_POST['first_name'] . "'");
                $row = mysqli_fetch_assoc($s);
              if ($s)
              { $_SESSION['user_name']=$_POST['user_name'];
                $_SESSION['first_name']=$_POST['first_name'];
                echo "<script type='text/javascript'>alert('Successful - Record Updated!'); window.location.href = 'profile.php';</script>"; }
            else
              { echo "<script type='text/javascript'>alert('Unsuccessful - ERROR!'); window.location.href = 'profile.php';</script>"; }
            }

?>

To me your code does just what you wrote about. Think about the record set you are dealing at line 10 and then 11. It looks like you selected all records then issued an UPDATE which would replace all records in this set.

I don't see where you write what you really wanted to happen.

You need a "WHERE".
"UPDATE user SET first_name ='" . $_POST['first_name'] . "' WHERE user_name='whatever'"
otherwise it will think you want to update everything in the first_name column.

You need to use where condtion on line 10, otherwise all records of the Database Table

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.