Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <title>Update a Record in MySQL Database</title>
  5. </head>
  6.  
  7. <body>
  8. <?php
  9. $username = "username";
  10. $password = "password";
  11. $hostname = "localhost";
  12.  
  13. //connection to the database
  14. $dbhandle = mysql_connect($hostname, $username, $password)
  15. or die("Unable to connect to MySQL");
  16. echo "Connected to MySQL<br>";
  17.  
  18. //select a database to work with
  19. $selected = mysql_select_db("database_dealers",$dbhandle)
  20. or die("Could not select dealers");
  21.  
  22. $ID = $_POST['ID'];
  23. $CName = $_POST['CName'];
  24.  
  25. $sql = "UPDATE `database_dealers`.`dealers` SET `CName` = 'newname' WHERE `dealers`.`ID` = 347;
  26. " ;
  27. mysql_select_db('database_dealers');
  28. $retval = mysql_query( $sql, $conn );
  29.  
  30. if(! $retval ) {
  31. die('Could not update data: ' . mysql_error());
  32. }
  33. echo "Updated data successfullyn";
  34.  
  35. mysql_close($conn);
  36.  
  37. ?>
  38. <form method = "post" action = "<?php $_PHP_SELF ?>">
  39. <table width = "400" border =" 0" cellspacing = "1"
  40. cellpadding = "2">
  41.  
  42. <tr>
  43. <td width = "100">Employee ID</td>
  44. <td><input name = "ID" type = "text"
  45. ID = "ID"></td>
  46. </tr>
  47.  
  48. <tr>
  49. <td width = "100">Employee Salary</td>
  50. <td><input name = "CName" type = "text"
  51. ID = "CName"></td>
  52. </tr>
  53.  
  54. <tr>
  55. <td width = "100"> </td>
  56. <td> </td>
  57. </tr>
  58.  
  59. <tr>
  60. <td width = "100"> </td>
  61. <td>
  62. <input name = "update" type = "submit"
  63. ID = "update" value = "Update">
  64. </td>
  65. </tr>
  66.  
  67. </table>
  68. </form>
  69. <?php
  70.  
  71. ?>
  72.  
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement