Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.19 KB | None | 0 0
  1. DATABASE
  2.  
  3. <?php
  4. class Database
  5. {
  6. private static $dbName = 'deb43619_koray' ;
  7. private static $dbHost = 'localhost' ;
  8. private static $dbUsername = 'deb43619_koray';
  9. private static $dbUserPassword = 'berkay5314';
  10.  
  11. private static $cont = null;
  12.  
  13. public function __construct() {
  14. die('Init function is not allowed');
  15. }
  16.  
  17. public static function connect()
  18. {
  19. // One connection through whole application
  20. if ( null == self::$cont )
  21. {
  22. try
  23. {
  24. self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
  25. }
  26. catch(PDOException $e)
  27. {
  28. die($e->getMessage());
  29. }
  30. }
  31. return self::$cont;
  32. }
  33.  
  34. public static function disconnect()
  35. {
  36. self::$cont = null;
  37. }
  38. }
  39. ?>
  40.  
  41.  
  42.  
  43. DOCENTPAGINA(INDEX)
  44. <!DOCTYPE html>
  45. <html lang="en">
  46. <head>
  47. <meta charset="utf-8">
  48. <link href="css/bootstrap.min.css" rel="stylesheet">
  49. <script src="css/bootstrap.min.js"></script>
  50. <script>
  51. function showUser(str)
  52. {
  53. if (str=="")
  54. {
  55. document.getElementById("txtHint").innerHTML="";
  56. return;
  57. }
  58. if (window.XMLHttpRequest)
  59. {// code for IE7+, Firefox, Chrome, Opera, Safari
  60. xmlhttp=new XMLHttpRequest();
  61. }
  62. else
  63. {// code for IE6, IE5
  64. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  65. }
  66. xmlhttp.onreadystatechange=function()
  67. {
  68. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  69. {
  70. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  71. }
  72. }
  73. xmlhttp.open("GET","getuser.php?q="+str,true);
  74. xmlhttp.send();
  75. }
  76. </script>
  77. </head>
  78.  
  79. <body>
  80. <div class="container">
  81. <div class="row">
  82. <h3>Leerlingen overzicht</h3>
  83. </div>
  84. <div class="row">
  85. <p>
  86. <a href="register.php" class="btn btn-success">Nieuwe leerling toevoegen</a>
  87. <a href="logout.php" class="btn btn-success">uitloggen</a>
  88. <form>
  89. <select name="users" onchange="showUser(this.value)">
  90. <option value="">Selecteer een groep:</option>
  91. <option value="1">Groep 1</option>
  92. <option value="2">Groep 2</option>
  93. <option value="3">Groep 3</option>
  94. <option value="4">Groep 4</option>
  95. <option value="5">Groep 5</option>
  96. <option value="6">Groep 6</option>
  97. <option value="7">Groep 7</option>
  98. <option value="8">Groep 8</option>
  99. <option value="">Alles</option>
  100. </select>
  101. </form>
  102. </p>
  103. <div id="txtHint">
  104. <table class="table table-striped table-bordered">
  105. <table class="table table-striped table-bordered">
  106. <thead>
  107. <tr>
  108. <th>Id</th>
  109. <th>Naam</th>
  110. <th>Wachtwoord</th>
  111. <th>Groep</th>
  112. <th>Action</th>
  113. </tr>
  114. </thead>
  115. <tbody>
  116. <?php
  117. include 'database.php';
  118. $pdo = Database::connect();
  119. $sql = 'SELECT * FROM leerling';
  120. foreach ($pdo->query($sql) as $row) {
  121. echo '<tr>';
  122. echo '<td>'. $row['id'] . '</td>';
  123. echo '<td>'. $row['username'] . '</td>';
  124. echo '<td>'. $row['password'] . '</td>';
  125. echo '<td>'. $row['groep'] . '</td>';
  126. echo '<td width=200>';
  127. echo '<a class="btn btn-success" href="update.php?id='.$row['id'].'">Update</a>';
  128. echo ' ';
  129. echo '<a class="btn btn-danger" href="delete.php?id='.$row['id'].'">Delete</a>';
  130. echo '</td>';
  131. echo '</tr>';
  132. }
  133. Database::disconnect();
  134. ?>
  135. </tbody>
  136. </table>
  137. </div>
  138. </div> <!-- /container -->
  139. </body>
  140. </html>
  141. <?php
  142. /* some code here */
  143.  
  144. show_source(__FILE__);
  145. ?>
  146.  
  147. TELT WAARDE OP
  148. INSERT INTO voorraad(Locatiecode,Productcode,Aantal) VALUES (1,1,10)
  149. ON DUPLICATE KEY UPDATE Aantal= Aantal + $aantal;
  150.  
  151. LOGIN
  152. <?php
  153. error_reporting(0);
  154. include("config.php");
  155. session_start();
  156.  
  157. if($_SERVER["REQUEST_METHOD"] == "POST") {
  158. // username and password sent from form
  159.  
  160. $myusername = mysqli_real_escape_string($db,$_POST['username']);
  161. $mypassword = mysqli_real_escape_string($db,$_POST['password']);
  162.  
  163. $sql = "SELECT id FROM docent WHERE username = '$myusername' and password = '$mypassword'";
  164. $result = mysqli_query($db,$sql);
  165. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  166. $active = $row['active'];
  167.  
  168. $count = mysqli_num_rows($result);
  169.  
  170. // If result matched $myusername and $mypassword, table row must be 1 row
  171.  
  172. if($count == 1) {
  173. // session_register("myusername");
  174. $_SESSION['login_user'] = $myusername;
  175.  
  176. header("location: docentpagina.php");
  177. }else {
  178. $error = "Your Login Name or Password is invalid";
  179. }
  180. }
  181. ?>
  182. <?php
  183. error_reporting(0);
  184. if($_SERVER["REQUEST_METHOD"] == "POST") {
  185. // username and password sent from form
  186.  
  187. $myusername = mysqli_real_escape_string($db,$_POST['username']);
  188. $mypassword = mysqli_real_escape_string($db,$_POST['password']);
  189.  
  190. $sql = "SELECT id FROM leerling WHERE username = '$myusername' and password = '$mypassword'";
  191. $result = mysqli_query($db,$sql);
  192. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  193. $active = $row['active'];
  194.  
  195. $count = mysqli_num_rows($result);
  196.  
  197. // If result matched $myusername and $mypassword, table row must be 1 row
  198.  
  199. if($count == 1) {
  200. // session_register("myusername");
  201. $_SESSION['login_user'] = $myusername;
  202.  
  203. header("location: leerlingpagina.php");
  204. }else {
  205. $error = "Your Login Name or Password is invalid";
  206. }
  207. }
  208. ?>
  209. <html>
  210.  
  211. <head>
  212. <title>Login Page</title>
  213.  
  214. <style type = "text/css">
  215. body {
  216. font:400 12px "Arial", sans-serif;
  217. color:#000;
  218. background:#000;
  219. }
  220. .header {
  221. margin-top:20px;
  222. }
  223. .wrapper {
  224. max-width:500px;
  225. width:95%;
  226. margin:0 auto;
  227. position:relative;
  228. }
  229. #contact-form input[type="text"],
  230. #contact-form input[type="password"],
  231. #contact-form textarea,
  232. #contact-form button[type="submit"] {
  233. font:100 16px/18px "Arial";
  234. }
  235. #contact-form button[name="submit1"] {
  236. font:100 16px/18px "Arial";
  237. }
  238.  
  239. #contact-form {
  240. text-shadow:0 1px 0 #FFF;
  241. border-radius:4px;
  242. -webkit-border-radius:4px;
  243. -moz-border-radius:4px;
  244. background:#F9F9F9;
  245. padding:25px;
  246. }
  247.  
  248. #contact-form label span {
  249. cursor:pointer;
  250. color:#006064;
  251. display:block;
  252. margin:5px 0;
  253. font-weight:900;
  254. font:100 16px/18px "monotype corsiva";
  255. }
  256. #contact-form input[type="text"],
  257. #contact-form input[type="password"],
  258. #contact-form textarea {
  259. width:100%;
  260. box-shadow:inset 0 1px 2px #DDD, 0 1px 0 #FFF;
  261. -webkit-box-shadow:inset 0 1px 2px #DDD, 0 1px 0 #FFF;
  262. -moz-box-shadow:inset 0 1px 2px #DDD, 0 1px 0 #FFF;
  263. border:1px solid #CCC;
  264. background:#FFF;
  265. margin:0 0 5px;
  266. padding:10px;
  267. border-radius:5px;
  268. }
  269. #contact-form input[type="text"]:hover,
  270. #contact-form input[type="password"]:hover,
  271. }
  272. #contact-form textarea {
  273. height:100px;
  274. max-width:100%;
  275. }
  276. #contact-form button[type="submit"] {
  277. cursor:pointer;
  278. width:100%;
  279. border:none;
  280. background:#000;
  281. color:#FFF;
  282. margin:0 0 5px;
  283. padding:10px;
  284. border-radius:5px;
  285. }
  286. #contact-form button[name="submit1"] {
  287. cursor:pointer;
  288. width:100%;
  289. border:none;
  290. background:#991D57;
  291. color:#FFF;
  292. margin:0 0 5px;
  293. padding:10px;
  294. border-radius:5px;
  295. }
  296. </style>
  297. </head>
  298.  
  299. <body>
  300.  
  301.  
  302. <div class="wrapper">
  303. <div id="main" style="padding:20px 0 0 0;">
  304. <form id="contact-form" action = "" method = "post">
  305. <label>Username :</label><input placeholder="Please enter your username" type = "text" name = "username" pattern=".{2,}" title="Minimal 2 symboles" required/><br /><br />
  306. <label>Password :</label><input placeholder="Please enter your password" type = "password" name = "password" pattern=".{2,}" title="Minimal 2 symboles" name="psw" required/><br/><br />
  307. <div>
  308. <button type = "submit" name="submit" value = " Submit ">Login</button>
  309. <div style = "font-size:11px; color:#cc0000; margin-top:10px"></div>
  310. </div>
  311. </form>
  312.  
  313.  
  314.  
  315. </div>
  316.  
  317. </div>
  318.  
  319. </div>
  320.  
  321. </body>
  322. </html>
  323.  
  324. LOGOUT
  325. <?php
  326. session_start();
  327.  
  328. if(session_destroy()) {
  329. header("Location: login.php");
  330. }
  331. ?>
  332.  
  333. CREATE
  334.  
  335. <?php
  336.  
  337. require 'database.php';
  338.  
  339. if ( !empty($_POST)) {
  340. // keep track validation errors
  341. $usernameError = null;
  342. $passwordError = null;
  343. $klasError = null;
  344.  
  345. // keep track post values
  346. $username = $_POST['username'];
  347. $password = $_POST['password'];
  348. $klas = $_POST['klas'];
  349.  
  350. // validate input
  351. $valid = true;
  352. if (empty($username)) {
  353. $usernameError = 'Please enter Name';
  354. $valid = false;
  355. }
  356.  
  357. if (empty($password)) {
  358. $passwordError = 'Please enter password';
  359. $valid = false;
  360. }
  361.  
  362. if (empty($klas)) {
  363. $klasError = 'Please enter klass';
  364. $valid = false;
  365. }
  366.  
  367. // insert data
  368. if ($valid) {
  369. $pdo = Database::connect();
  370. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  371. $sql = "INSERT INTO leerling (username,password,klas) values(?, ?, ?)";
  372. $q = $pdo->prepare($sql);
  373. $q->execute(array($username,$password,$klas));
  374. Database::disconnect();
  375. header("Location: welcome1.php");
  376. }
  377. }
  378. ?>
  379. <!DOCTYPE html>
  380. <html lang="en">
  381. <head>
  382. <meta charset="utf-8">
  383. <link href="css/bootstrap.min.css" rel="stylesheet">
  384. <script src="css/bootstrap.min.js"></script>
  385. </head>
  386.  
  387. <body>
  388. <div class="container">
  389.  
  390. <div class="span10 offset1">
  391. <div class="row">
  392. <h3>Create a student</h3>
  393. </div>
  394.  
  395. <form class="form-horizontal" action="create.php" method="post">
  396. <div class="control-group <?php echo !empty($nameError)?'error':'';?>">
  397. <label class="control-label">Name</label>
  398. <div class="controls">
  399. <input name="username" type="text" placeholder="Name" value="<?php echo !empty($username)?$username:'';?>">
  400. <?php if (!empty($usernameError)): ?>
  401. <span class="help-inline"><?php echo $usernameError;?></span>
  402. <?php endif; ?>
  403. </div>
  404. </div>
  405. <div class="control-group <?php echo !empty($passwordError)?'error':'';?>">
  406. <label class="control-label">Password</label>
  407. <div class="controls">
  408. <input name="password" type="text" placeholder="Password" value="<?php echo !empty($password)?$password:'';?>">
  409. <?php if (!empty($passwordError)): ?>
  410. <span class="help-inline"><?php echo $passwordError;?></span>
  411. <?php endif;?>
  412. </div>
  413. </div>
  414. <div class="control-group <?php echo !empty($klasError)?'error':'';?>">
  415. <label class="control-label">Klass</label>
  416. <div class="controls">
  417. <input name="klas" type="text" placeholder="klas" value="<?php echo !empty($klas)?$klas:'';?>">
  418. <?php if (!empty($klasError)): ?>
  419. <span class="help-inline"><?php echo $klasError;?></span>
  420. <?php endif;?>
  421. </div>
  422. </div>
  423. <div class="form-actions">
  424. <button type="submit" class="btn btn-success">Create</button>
  425. <a class="btn" href="welcome1.php">Back</a>
  426. </div>
  427. </form>
  428. </div>
  429.  
  430. </div> <!-- /container -->
  431. </body>
  432. </html>
  433. <?php
  434. /* some code here */
  435.  
  436. show_source(__FILE__);
  437. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement