Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Update a Record in MySQL Database</title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8. $dbhost = 'localhost';
  9. $dbuser = 'root';
  10. $dbpass = '';
  11. $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  12. if(! $conn )
  13. {
  14.   die('Could not connect: ' . mysql_error());
  15. }
  16. mysql_select_db("employees", $conn);
  17.  
  18. if(isset($_POST['update'])){
  19. $UpdateQuery = "UPDATE employee SET emp_name='$_POST[emp_name]', emp_address='$_POST[emp_address]', emp_salary='$_POST[emp_salary]', emp_cnp='$_POST[emp_cnp]', emp_phone='$_POST[emp_phone]', join_date='$_POST[join_date]' WHERE emp_id='$_POST[hidden]'";              
  20. mysql_query($UpdateQuery, $conn);
  21. };
  22.  
  23. if(isset($_POST['delete'])){
  24. $DeleteQuery = "DELETE FROM employee WHERE emp_id='$_POST[hidden]'";          
  25. mysql_query($DeleteQuery, $conn);
  26. };
  27.  
  28.  
  29. $sql = "SELECT * FROM employee";
  30. $myData = mysql_query($sql,$conn);
  31. echo "<table border=1px>
  32. <tr>
  33. <th>Name</th>
  34. <th>Address</th>
  35. <th>Salariu</th>
  36. <th>CNP</th>
  37. <th>Telefon</th>
  38. <th>Data Angajari</th>
  39. </tr>";
  40. while($record = mysql_fetch_array($myData)){
  41. echo "<form action=updata2.php method=post>";
  42. echo "<tr>";
  43. echo "<td>" . "<input type=text name=emp_name value=" . $record['emp_name'] . " </td>";
  44. echo "<td>" . "<input type=text name=emp_address value=" . $record['emp_address'] . " </td>";
  45. echo "<td>" . "<input type=text name=emp_salary value=" . $record['emp_salary'] . " </td>";
  46. echo "<td>" . "<input type=text name=emp_cnp value=" . $record['emp_cnp'] . " </td>";
  47. echo "<td>" . "<input type=text name=emp_phone value=" . $record['emp_phone'] . " </td>";
  48. echo "<td>" . "<input type=text name=join_date value=" . $record['join_date'] . " </td>";
  49. echo "<td>" . "<input type=hidden name=hidden value=" . $record['emp_id'] . " </td>";
  50. echo "<td>" . "<input type=submit name=update value=update" . " </td>";
  51. echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
  52. echo "</tr>";
  53. echo "</form>";
  54. echo "</table>";
  55. }
  56. mysql_close($conn);
  57.  
  58. ?>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement