Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2. $userid = $_GET['id'];
  3. $dbhost = "localhost";
  4. $dbname = "cucurema";
  5. $username = "root";
  6. $password = "";
  7.  
  8. $connectie = mysqli_connect($dbhost, $username,$password,$dbname);
  9.  
  10. if(!$connectie)
  11. {
  12. echo "connectie niet geslaagd";
  13. echo mysqli_error();
  14.  
  15. }else{
  16. echo "connectie geslaagd";
  17. }
  18.  
  19. $query = "SELECT naam, adres, email ";
  20. $query .="FROM klant ";
  21. $query .="WHERE id =" . $userid;
  22.  
  23. $escapedQuery = mysqli_real_escape_string($connectie, $query);
  24.  
  25. $result = mysqli_query($connectie, $escapedQuery);
  26. if(!$result)
  27. {
  28. echo mysqli_error($connectie);
  29. }
  30.  
  31.  
  32. ?>
  33.  
  34. <html>
  35. <head>
  36. </head>
  37. <body>
  38. <form method="POST">
  39. <table>
  40. <?php
  41. foreach($result as $row)
  42. { ?>
  43. <tr><td>Naam <input type="text" name="naam" value= '<?php echo $row['naam'];?>'/></td></tr>
  44. <tr><td>adres <input type="text" name="adres" value= '<?php echo $row['adres'];?>' /></td></tr>
  45. <tr><td>email <input type="text" name="email" value= '<?php echo $row['email'];?>' /></td></tr>
  46. <tr><td><input type="submit" name="btnupdate" value="klik"/></td></tr>
  47. <?php }?>
  48. <?php
  49. if(isset($_POST['btnupdate']))
  50. {
  51.  
  52. $userid = $_GET['id'];
  53. $firstname = mysqli_real_escape_string($connectie, $_POST['naam']);
  54. $adres = mysqli_real_escape_string($connectie, $_POST['adres']);
  55. $email = mysqli_real_escape_string($connectie, $_POST['email']);
  56.  
  57.  
  58. $updatequery='update klant ';
  59. $updatequery .='SET naam="'.$firstname.'", adres = "'.$adres. '", email="'.$email.'" ';
  60. $updatequery .='WHERE id='. $userid;
  61.  
  62.  
  63. $result = mysqli_query($connectie, $updatequery);
  64. if(!$result)
  65. {
  66. echo mysqli_error($connectie);
  67. echo 'ging fout';
  68. }else{
  69. echo 'ging goed';
  70. header('Location: opdracht1.4.php ');
  71. }
  72. }
  73. ?>
  74. </table>
  75. </form>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement