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 Answer