I have this program -
To Develop a php application to modify salary of an employee,your application should provide facility to choose an employee from a drop-down list.
I tried with the following code but it cannot change the record in the table "emp" inside the "db1" database. There are 3 pages in total. The table "emp" has 3 fields -emp_id,ename,salary.
Here is the code-
1)emp_select.php-
2)emp_mod.php -Code:<html> <head> <title></title> </head> <body> <form action="emp_mod.php" method="post"> Choose an employee <select name="emp"> <?php $host="localhost"; $user="root"; $passwd=""; $con=mysql_connect($host,$user,$passwd); mysql_select_db('db1',$con); $sql="select emp_id,ename from emp"; $result=mysql_query($sql,$con); ?> <input type="submit" value="show"> </form> </body> </html>
3)emp_upd.php-Code:<html> <head> <title>Untitled Document</title> </head> <body> <?php $eid=$_POST['emp']; $con=mysql_connect('localhost','root',''); mysql_select_db('db1',$con); $sql="select ename,salary from emp where emp_id='$eid'"; $result=mysql_query($sql,$con); $rec=mysql_fetch_row($result); $enm=$rec[0]; $sal=$rec[1]; ?> <form action="emp_upd.php" mehtod="post"> Emp. ID <input type="text" name="eid" value="<?php echo $eid; ?>" readonly="readonly"><br /> Emp. Name: <input type="text" readonly="readonly" name="enm" value="<?php echo $enm;?>"><br /> Mthly Salary: <input type="text" name="sal" value="<?php echo $sal;?>"><br /> <br /> <input type="submit" value="Save"> </form> </body> </html>
Where can be the problem in the above code?Code:<?php $eid=$_POST['eid']; $sal=$_POST['sal']; $con=mysql_connect('localhost','root',''); mysql_select_db('db1',$con); $sql="update emp set salary='$sal' where emp_id='$eid'"; if(mysql_query($sql,$con)) { echo "Record changed<br>"; } else { die('Unable to change salary<br>'); } ?>
Pls help
Thanks in advance



Reply With Quote
Bookmarks