Advertisement
Guest User

Padėkite :)

a guest
Jan 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. //Čia mano html puslapis
  2.  
  3. <!DOCTYPE HTML>
  4.  
  5. <html>
  6.  
  7. <head>
  8.  
  9. <title>Home page</title>
  10.  
  11. </head>
  12.  
  13. <body>
  14.  
  15. <form action="studentAdded.php" method="register">
  16.  
  17. <h1>Home</h1>
  18.  
  19. <h2>Register an user!</h2>
  20.  
  21. Username: <input type="text" name="username" size="30" value=""></input><br>
  22. Password: <input type="text" name="password" size="30" value=""></input><br>
  23. Email: <input type="text" name="email" size="30" value=""></input><br>
  24. <input type="submit" name="submit" value="Send" ><br>
  25.  
  26. </form>
  27.  
  28. <body>
  29.  
  30. </html>
  31.  
  32. //Čia mano studentAdded.php
  33.  
  34.  
  35. <html>
  36.  
  37. <head>
  38.  
  39. <title>Home page</title>
  40.  
  41. </head>
  42.  
  43. <body>
  44.  
  45. <?php
  46.  
  47. if(isset($_POST['submit'])){
  48.  
  49. $data_missing = array();
  50.  
  51. if(empty($_POST['username'])){
  52.  
  53. // Adds name to array
  54. $data_missing[] = 'Username';
  55.  
  56. } else {
  57.  
  58. // Trim white space from the name and store the name
  59. $UserName = trim($_POST['username']);
  60.  
  61. }
  62.  
  63. if(empty($_POST['password'])){
  64.  
  65. // Adds name to array
  66. $data_missing[] = 'Password';
  67.  
  68. } else{
  69.  
  70. // Trim white space from the name and store the name
  71. $PassWord = trim($_POST['password']);
  72.  
  73. }
  74.  
  75. if(empty($_POST['email'])){
  76.  
  77. // Adds name to array
  78. $data_missing[] = 'Email';
  79.  
  80. } else{
  81.  
  82. // Trim white space from the name and store the name
  83. $Email = trim($_POST['email']);
  84.  
  85. }
  86.  
  87. if(empty($data_missing)){
  88.  
  89. require_once('../../mysqli_connect.php');
  90.  
  91. $query = "INSERT INTO users (username, password, email) VALUES (?, ?, ?)";
  92.  
  93. $stmt = mysqli_prepare($dbc, $query);
  94.  
  95. mysqli_stmt_bind_param($stmt, "sss", $UserName, $PassWord, $Email);
  96.  
  97. mysqli_stmt_execute($stmt);
  98.  
  99. $affected_rows = mysqli_stmt_affected_rows($stmt);
  100.  
  101. if($affected_rows == 1){
  102.  
  103. echo 'Student Entered';
  104.  
  105. mysqli_stmt_close($stmt);
  106.  
  107. mysqli_close($dbc);
  108.  
  109. } else {
  110.  
  111. echo 'Error Occurred<br />';
  112. echo mysqli_error();
  113.  
  114. mysqli_stmt_close($stmt);
  115.  
  116. mysqli_close($dbc);
  117.  
  118. }
  119.  
  120. } else {
  121.  
  122. echo 'You need to enter the following data<br />';
  123.  
  124. foreach($data_missing as $missing){
  125.  
  126. echo "$missing<br />";
  127.  
  128. }
  129.  
  130. }
  131.  
  132. }
  133.  
  134. ?>
  135.  
  136. <form action="studentAdded.php" method="register">
  137.  
  138. <h1>Home</h1>
  139.  
  140. <h2>Register an user!</h2>
  141.  
  142. Username: <input type="text" name="username" size="30" value="" ></input><br>
  143. Password: <input type="text" name="password" size="30" value="" ></input><br>
  144. Email: <input type="text" name="email" size="30" value="" ></input><br>
  145. <input type="submit" name="submit" value="Send"><br>
  146.  
  147. </form>
  148.  
  149. <body>
  150.  
  151. </html>
  152.  
  153. //Čia mano tas msqli-connect.php
  154.  
  155. <?php
  156. DEFINE ('DB_USER', 'root');
  157. DEFINE ('DB_PASSWORD', 'elkaso75');
  158. DEFINE ('DB_HOST', 'localhost');
  159. DEFINE ('DB_NAME', 'kudzewebsites');
  160.  
  161. $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
  162. OR die('Could not connect to MySQL: ' .
  163. mysqli_connect_error());
  164. ?>
  165.  
  166.  
  167. //O čia mano php failas, per kurį bandau parodyt savo mysql lentelę
  168.  
  169. <?php
  170. // Prijungia prie mysql
  171. require_once('../../mysqli_connect.php');
  172.  
  173. // Sukuria query
  174. $query = "SELECT username, password, email FROM users";
  175.  
  176. // Get a response from the database by sending the connection
  177. // and the query
  178. $response = @mysqli_query($dbc, $query);
  179.  
  180. // If the query executed properly proceed
  181. if($response){
  182.  
  183. echo '<table align="left"
  184. cellspacing="5" cellpadding="8">
  185.  
  186. <tr><td align="left"><b>Username</b></td>
  187. <td align="left"><b>Password</b></td>
  188. <td align="left"><b>Email</b></td></tr>';
  189.  
  190. // mysqli_fetch_array will return a row of data from the query
  191. // until no further data is available
  192. while($row = mysqli_fetch_array($response)){
  193.  
  194. echo '<tr><td align="left">' .
  195. $row['username'] . '</td><td align="left">' .
  196. $row['password'] . '</td><td align="left">' .
  197. $row['email'] . '</td>';
  198.  
  199. echo '</tr>';
  200. }
  201.  
  202. echo '</table>';
  203.  
  204. } else {
  205.  
  206. echo "Couldn't issue database query<br />";
  207.  
  208. echo mysqli_error($dbc);
  209.  
  210. }
  211.  
  212. // Close connection to the database
  213. mysqli_close($dbc);
  214.  
  215. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement