Advertisement
Guest User

title

a guest
Apr 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. The Error Messages: http://prntscr.com/awsb5m
  2. The Code:
  3.  
  4. <html>
  5. <head>
  6. <title>Add User</title>
  7. </head>
  8. <body>
  9. <?php
  10.  
  11. if(isset($_POST['submit'])){
  12.  
  13. $data_missing = array();
  14.  
  15. if(empty($_POST['username'])){
  16.  
  17. // Adds name to array
  18. $data_missing[] = 'Username';
  19.  
  20. } else {
  21.  
  22. // Trim white space from the name and store the name
  23. $username = trim($_POST['username']);
  24.  
  25. }
  26.  
  27. if(empty($_POST['password'])){
  28.  
  29. // Adds name to array
  30. $data_missing[] = 'Password';
  31.  
  32. } else{
  33.  
  34. // Trim white space from the name and store the name
  35. $password = trim($_POST['password']);
  36.  
  37. }
  38.  
  39.  
  40. if(empty($_POST['email'])){
  41.  
  42. // Adds name to array
  43. $data_missing[] = 'Email';
  44.  
  45. } else {
  46.  
  47. // Trim white space from the name and store the name
  48. $email = trim($_POST['email']);
  49.  
  50. }
  51.  
  52. if(empty($data_missing)){
  53.  
  54. require_once('../mysqli_connect.php');
  55.  
  56. $query = "INSERT INTO user_details (username, password, email) VALUES (?, ?)";
  57.  
  58. $stmt = mysqli_prepare($dbc, $query);
  59.  
  60. mysqli_stmt_bind_param($stmt, "ss", $username, $password, $email);
  61.  
  62. mysqli_stmt_execute($stmt);
  63.  
  64. $affected_rows = mysqli_stmt_affected_rows($stmt);
  65.  
  66. if($affected_rows == 1){
  67.  
  68. echo 'User Entered';
  69.  
  70. mysqli_stmt_close($stmt);
  71.  
  72. mysqli_close($dbc);
  73.  
  74. } else {
  75.  
  76. echo 'Error Occurred<br />';
  77. echo mysqli_error();
  78.  
  79. mysqli_stmt_close($stmt);
  80.  
  81. mysqli_close($dbc);
  82.  
  83. }
  84.  
  85. } else {
  86.  
  87. echo 'You need to enter the following data<br />';
  88.  
  89. foreach($data_missing as $missing){
  90.  
  91. echo "$missing<br />";
  92.  
  93. }
  94.  
  95. }
  96.  
  97. }
  98.  
  99. ?>
  100.  
  101. <form action="http://localhost/useradded.php" method="post">
  102.  
  103. <b>Add a New User</b>
  104.  
  105. <p>Username:
  106. <input type="text" name="username" size="30" value="" />
  107. </p>
  108.  
  109. <p>Password:
  110. <input type="password" name="password" size="30" value="" />
  111. </p>
  112.  
  113. <p>Email:
  114. <input type="text" name="email" size="30" value="" />
  115. </p>
  116.  
  117. <p>
  118. <input type="submit" name="submit" value="Send" />
  119. </p>
  120.  
  121. </form>
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement