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 5970105
In Process

The Archive Base Latest Questions

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

The situation is my program’s purpose is to update employee details. The user may

  • 0

The situation is my program’s purpose is to update employee details. The user may choose which of the information (name,position,department and tag(which tells if he/she is still employed to the company)) he/she wants to update. He or she may or may not fill up all the details as he/she wants to. In other words,he/she may leave it blank if he/she is not going to change that certain information.

MY PROBLEM IS the updating. it is now updating. But then for example,if the user wants to change only the position information of that employee,he/she will leave the name,department blank.(tag is by default set to yes so there is always a value). when the user clicks the submit button. it updates the table BUT it updates the empty text box to spaces. meaning, in the example. In the database, the name and department will contain “spaces”.

MY GOAL is that,if the user leaves a text box empty,the original value should remain. it will only change the inputed values.


here is the code i used in my empinfo.php (NOTE: this one is a pop up,the emp, came from the index,but there is no problem about that 😀 )

<body>
<center>
<table class="main" border="0" cellpadding="0" cellspacing="0"> 
<form action="empinfo.php" method="POST">
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='eid' id='eid' value= '<?php echo $_GET['emp']?>' />  

<fieldset>
            <div class='container'>
                <label for='ename' >Employee name:</label><br/>
                <input type='text' name='ename' id='ename' maxlength="50" /><br/><br/>
             </div>

             <div class='container'>
                <label for='pos' >Position:</label><br/>
                <input type='text' name='pos' id='pos' maxlength="50" /><br/><br/>
             </div>

            <div class='container'>
                <label for='dep' >Department/Division:</label><br/>
                <input type='text' name='dep' id='dep' maxlength="100" /><br/><br/>
            </div>

            <div class='container'>
                <label for='tag' >Employee Tag:</label><br/>
                <select name="tag" id="tag">
                    <option value="Y">Yes</option>
                    <option value="N">No</option>
                </select> <br/><br/>
            </div>

            <div class='container'>
                <input type='submit' name='Submit' value='Submit' />
            </div>
</fieldset>

</form>
</div>
<?php   
$con=mysql_connect('localhost','root','mariel') or die(mysql_error());
mysql_select_db('intranet',$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 
        }       
    ?>
</table>
<?php mysql_close($con); ?>
</center>
</body>
  • 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:19:35+00:00Added an answer on May 22, 2026 at 8:19 pm
    $col['emp_name'] = (trim($_POST['ename']))?trim($_POST['ename']):false;
    $col['emp_pos']  = (trim($_POST['pos']))?trim($_POST['pos']):false;
    $col['emp_dep']  = (trim($_POST['dep']))?trim($_POST['dep']):false;
    $col['emp_tag']  = (trim($_POST['tag']))?trim($_POST['tag']):false;
    // add a val in $col[] with key=column name for each corresponding $_POST val
    
    $queryString ="UPDATE `gpl_employees_list` SET ";
    foreach($col as $key => $val){
      $queryString .= ($val)?"`".$key."`='".$val."',":"";
    }
    $queryString = substr($queryString ,0 ,strlen($queryString) - 1 )." WHERE `emp_id` = '".$_POST['eid']."'"; 
    mysql_query($queryString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation: I have program A which looks like this: Fmfile IF
I got a situation where the client got 'C' program which does encryption of
Situation: I have a C# program which does the following: Generate many files (replacing
I have a situation where there is a program which is written in c++.
let us have a situation in which the following program prints some 10 lines
My situation: I'm running a C# testing program which allows me to configure certain
This is the situation : I mostly program C# and have written types in
I have a situation where I want my program to read in some numbers
Hypothetical situation. I have a command line program in *nix (linux, BSD, etc.). It
I have following situation: String a = A Web crawler is a computer program

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.