Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:10:19+00:00 2026-05-22T20:10:19+00:00

i am doing a project where one may update the name, position, department and

  • 0

i am doing a project where one may update the name, position, department and tag of the employee.

But as i do my project, it wont update, i know there is something wrong with my code. would you guys mind checking it.

my php page has an index.php which is the main menu, if you click the employee name in the list, a pop up window will appear. that pop up is for updating.

my php code (it now updating) but errors found:

<?php
$con=mysql_connect('localhost','root','pss') or die(mysql_error());
mysql_select_db('intra',$con);

if(isset($_POST['submitted']))
    {

    $sql = "SELECT * FROM gpl_employees_list where emp_id='".$_POST['eid']."'";
    $result = mysql_query($sql) or die (mysql_error());
    if(!$result || mysql_num_rows($result) <= 0)
                            {                       
                                return false;
                            }

    $qry = "UPDATE gpl_employees_list SET emp_nme = '".$_POST['ename']."', emp_pos = '".$_POST['pos']."', emp_dep = '".$_POST['dep']."', emp_tag = '".$_POST['tag']."' WHERE emp_id = '".$_POST['eid']."' ";  

    mysql_query($qry) or die (mysql_error()); 
?><script>window.close();</script><?php 
        }       
    ?>

*NOTE : this is now updating, but if a user leaves one of the textboxes empty, it updates the table with empty spaces as well and that is my problem now. how do i avoid that? i mean if a user leaves one textbox empty,the data with empty values must still contain its old value,but how to do that with this code? thanks for those who will help

MisaChan
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:10:20+00:00Added an answer on May 22, 2026 at 8:10 pm

    You use $_POST for ‘name/pos/dep/tag’ and $_GET for ’emp’ so you’re probably not getting the values.
    Change the GETs to POST – that should do it.
    Since you’re updating, I’d recommend using POST over GET.
    GET is more appropriate for searching.

    Also, you can put all your update queries into one update query.
    Like so.

    $name = $_POST['name'];
    $pos = $_POST['pos'];
    $dep = $_POST['dep'];
    $tag = $_POST['tag'];
    $emp = $_POST['emp'];
    
    $qry_start = "UPDATE gpl_employees_list SET ";
    $where = " WHERE emp_id = $emp";
    $fields = "";
    $updates = "";
    
    if($name){
      $updates .= " `emp_name` = $name,";
    }
    if($pos){
      $updates .= " `emp_pos` = $pos,";
    }
    if($dep){
      $updates .= " `emp_dep` = $dep,";
    }
    if($tag){
      $updates .= " `emp_tag` = $tag,";
    }
    $updates = substr($updates, 0, -1); //To get rid of the trailing comma.
    $qry = $qry_start . $updates . $where;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my 1st C# project so I may be doing something obviously improper
I am very new to grails.I am doing one sample project for image uploading
I'm about to start a project where I will be the only one doing
For an art project, one of the things I'll be doing is zooming in
I'm currently working on a project in which at one point, the user may
Doing some initial research on a new project and one of my requirements is
I'm doing a code review for one project. It's architecture you can see on
I am doing project euler question 33 and have divised a refactor to solve
After doing a project with WPF and getting very much attached to it's excellent
Im doing a project with C# winforms. This project is composed by: alt text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.