Advertisement
Guest User

Untitled

a guest
Jun 5th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  1. include ("connection.php");
  2.  
  3.  
  4.  
  5. echo "<form method='post'>";
  6. echo "Search For User: <input type='text' name='searchString' />";
  7. echo "<input type='submit' name='search' value='search' />";
  8.  
  9.  
  10. if(isset($_POST['search']))
  11. {
  12. if(strlen($_REQUEST['searchString']))
  13. {
  14. $sql="SELECT * FROM login WHERE username LIKE '%".$_REQUEST['searchString']."%'";
  15. $result=$conn->query($sql);
  16.  
  17. echo "<table border=1><tr><th>id</th><th>username</th><th>password</th><th>image</th><th>date</th><th>comments</th></tr>";
  18. while($test = $result->fetch_assoc())
  19. {
  20. echo "<tr align='center'><td>".$test['id']."</td><td>".$test['username']."</td><td>".$test['password']."</td>";
  21. echo "<td><img src=".$test['imagepath']." style='width:50px; height:50px;' /></td><td>".$test['date']."</td><td>".$test['comment']."</td><td><input type='checkbox' name='deletecb[]' value=".$test['id']." /></td></tr>";
  22. }
  23. echo "<tr><td><input type='submit' name='edit' value='edit' /></td><td><input type='submit' name='search' value='search' /></td><td><input type='submit' name='delete' value='delete' /></td></tr>";
  24. echo "</table>";
  25. }
  26.  
  27. }
  28.  
  29. if(isset($_POST['edit']))
  30. {
  31. header("Location:edit.php");
  32. exit();
  33. }
  34.  
  35. echo "</form>";
  36. ?>
  37.  
  38. <?PHP
  39.  
  40. include ("connection.php");
  41.  
  42. $sql="SELECT * FROM login";
  43. $result=$conn->query($sql);
  44.  
  45.  
  46. if($result->num_rows>0)
  47. {
  48. echo "<form method='post' enctype='multipart/form-data'>";
  49.  
  50. echo "<table border=1><tr><th>id</th><th>username</th><th>password</th><th>image</th><th>date</th><th>comments</th></tr>";
  51. while($test = $result->fetch_assoc())
  52. {
  53. echo $test['comment'];
  54. echo "<tr align='center'><td><input type='hidden' name='id[]' value=" . $test['id'] . " />" . $test['id'] . "</td><td><input type='text' name='username[]' value=" . $test['username'] . " /></td><td><input type='text' name='password[]' value=" . $test['password'] . " /></td><td><img src=".$test['imagepath']." style='width:50px; height:50px;' /><input type='hidden' name='imagepath[]' value=" . $test['imagepath'] . " /><br><input type='file' name='fileToUpload[]' accept='image/*' /></td><td><input type='date' name='date[]' value=" . $test['date'] . " /></td><td><input type='text' name='comment[]' value='".$test['comment']."' /></td></tr>";
  55. }
  56. echo "<tr><td></td><td><input type='submit' name='done' value='done' /></td></tr>";
  57. echo "</table> </form>";
  58. }
  59.  
  60.  
  61.  
  62. if(isset($_POST['done']))
  63. {
  64. print_r($_POST);
  65. echo "<br><br>";
  66. echo "following values are updates:<br>";
  67.  
  68. $target_dir = "images/";
  69.  
  70.  
  71.  
  72.  
  73.  
  74. for ($i = 0; $i < count($_POST['id']); $i++)
  75. {
  76.  
  77. //$_FILES['fileToUpload']['name'][$i] will get just image name
  78. if(strlen($_FILES['fileToUpload']['name'][$i]))
  79. {
  80. $target_file = $target_dir . basename($_FILES['fileToUpload']['name'][$i]);
  81. }
  82. else
  83. {
  84. $target_file = $_POST['imagepath'][$i];
  85. }
  86.  
  87. //to upload images
  88. move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$i], $target_file);
  89.  
  90.  
  91. echo $_POST['id'][$i]." ".$_POST['username'][$i]." ".$_POST['password'][$i]." ".$_FILES['fileToUpload']['name'][$i];
  92. echo $id;
  93. echo "<br>";
  94.  
  95. $id=$_REQUEST['id'][$i];
  96. $username=$_REQUEST['username'][$i];
  97. $password=$_REQUEST['password'][$i];
  98. $date=$_REQUEST['date'][$i];
  99. $comment=$_REQUEST['comment'][$i];
  100.  
  101. echo "<br>";
  102. $sql="UPDATE login SET username='". $username. "',password='". $password ."',imagepath='". $target_file ."',date='". $date ."',comment='". $comment ."' WHERE id=". $id;
  103. //$sql="UPDATE login SET username='briano',password='briano' WHERE id='7'";
  104. $conn->query($sql);
  105. }
  106. //header("Refresh:0");
  107.  
  108. header("Location:display.php");
  109.  
  110. /* foreach( $_POST as $stuff ) {
  111. if( is_array( $stuff ) ) {
  112. foreach( $stuff as $thing ) {
  113. echo "<br>";
  114. echo $thing;
  115. }
  116. } else {
  117. echo "<br>";
  118. echo $stuff;
  119. }
  120. }
  121. */
  122. }
  123.  
  124.  
  125. echo "</form>";
  126. ?>
  127.  
  128. <?php
  129. include('config.php');
  130. session_start();
  131.  
  132. $user_check = $_SESSION['login_user'];
  133.  
  134. $ses_sql = mysqli_query($db,"select username from admin where username = '$user_check' ");
  135.  
  136. $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
  137.  
  138. $login_session = $row['username'];
  139.  
  140. if(!isset($_SESSION['login_user'])){
  141. header("location:login.php");
  142. }
  143. ?>
  144.  
  145. <?php
  146. include('connection.php');
  147. session_start();
  148. ?>
  149. <html">
  150.  
  151. <head>
  152. <title>Welcome </title>
  153. </head>
  154.  
  155. <body>
  156. <h1>Welcome <?php echo $_SESSION['login_user']; ?></h1>
  157. <h2><a href = "logout.php">Sign Out</a></h2>
  158. </body>
  159.  
  160. </html>
  161.  
  162. <?PHP
  163. $host="localhost";
  164. $username="root";
  165. $password="";
  166. $dbname="company";
  167.  
  168. $conn=new mysqli($host, $username, $password, $dbname);
  169.  
  170. if($conn->connect_error)
  171. {
  172. die("connection error" . $conn->connect_error);
  173. }
  174. ?>
  175.  
  176. <html>
  177.  
  178.  
  179. <table border="1">
  180.  
  181.  
  182.  
  183. <tr>
  184. <th>id</th>
  185. <th>username</th>
  186. <th>password</th>
  187. <th>image</th>
  188. <th>date</th>
  189. <th>comments</th>
  190. </tr>
  191.  
  192. <?PHP
  193.  
  194. include ("connection.php");
  195.  
  196.  
  197. $sql="SELECT * FROM login ORDER BY date";
  198. $result=$conn->query($sql);
  199.  
  200.  
  201. if($result->num_rows>0)
  202. {
  203. echo "<form method='post'>";
  204. while($test = $result->fetch_assoc())
  205. {
  206. ?>
  207. <tr>
  208. <td><?php echo $test['id']; ?></td>
  209. <td><?php echo $test['username']; ?></td>
  210. <td><?php echo $test['password']; ?></td>
  211. <td><img src="<?php echo $test['imagepath']; ?>" style='width:50px; height:50px;' /></td>
  212. <td><?php echo $test['date']; ?></td>
  213. <td><?php echo $test['comment']; ?></td>
  214. <td><input type='checkbox' name='deletecb[]' value="<?php echo $test['id']; ?>" /></td>
  215. </tr>
  216.  
  217. <?php } ?>
  218. <tr>
  219. <td> <input type='submit' name='edit' value='edit' /> </td>
  220. <td> <input type='submit' name='search' value='search' /> </td>
  221. <td> <input type='submit' name='delete' value='delete' /> </td>
  222. </tr>
  223. </form>
  224. </table>
  225.  
  226. <?php } ?>
  227.  
  228. </html>
  229. <?PHP
  230.  
  231. include ("connection.php");
  232.  
  233.  
  234. $sql="SELECT * FROM login ORDER BY date";
  235. $result=$conn->query($sql);
  236.  
  237.  
  238. if($result->num_rows>0)
  239. {
  240. echo "<form method='post'>";
  241. echo "<table border=1><tr><th>id</th><th>username</th><th>password</th><th>image</th><th>date</th><th>comments</th></tr>";
  242. while($test = $result->fetch_assoc())
  243. {
  244. echo "<tr align='center'><td>".$test['id']."</td><td>".$test['username']."</td><td>".$test['password']."</td>";
  245. echo "<td><img src=".$test['imagepath']." style='width:50px; height:50px;' /></td><td>".$test['date']."</td><td>".$test['comment']."</td><td><input type='checkbox' name='deletecb[]' value=".$test['id']." /></td></tr>";
  246. }
  247. echo "<tr><td><input type='submit' name='edit' value='edit' /></td><td><input type='submit' name='search' value='search' /></td><td><input type='submit' name='delete' value='delete' /></td></tr>";
  248. echo "</table>";
  249. }
  250.  
  251. if(isset($_POST['search']))
  252. {
  253. echo "coming";
  254. header("Location:search.php");
  255. exit();
  256.  
  257. }
  258.  
  259.  
  260. if(isset($_POST['delete']))
  261. {
  262. $deleteCb=$_REQUEST['deletecb'];
  263. for($i=0;$i<count($deleteCb);$i++)
  264. {
  265. $id=$deleteCb[$i];
  266. $sql="DELETE FROM login WHERE id=".$id;
  267. $conn->query($sql);
  268. }
  269. header("Refresh:0");
  270. }
  271.  
  272.  
  273.  
  274.  
  275. if(isset($_POST['edit']))
  276. {
  277. header("Location:edit.php");
  278. exit();
  279. }
  280.  
  281. echo "</form>";
  282. ?>
  283.  
  284. <html>
  285. <head>
  286. </head>
  287. <body>
  288. <form method="post">
  289. username: <input type="user" name="user">
  290. password: <input type="pass" name="pass">
  291. <input type="submit" name="add" value="add">
  292.  
  293. <?PHP
  294.  
  295.  
  296.  
  297. if(isset($_POST['add']))
  298. {
  299. //store form variables
  300. $user=$_POST['user'];
  301. $pass=$_POST['pass'];
  302.  
  303. //make connection
  304. include("connection.php");
  305.  
  306. //insert query
  307. $sql="INSERT INTO login(username,password) VALUES ('$user','$pass')";
  308. $conn->query($sql);
  309. }
  310.  
  311. include("display.php");
  312.  
  313. ?>
  314. </form>
  315. </body>
  316. </html>
  317.  
  318. <html>
  319.  
  320. <head>
  321. <title>Login Page</title>
  322.  
  323. <style type = "text/css">
  324. body {
  325. font-family:Arial, Helvetica, sans-serif;
  326. font-size:14px;
  327. }
  328.  
  329. label {
  330. font-weight:bold;
  331. width:100px;
  332. font-size:14px;
  333. }
  334.  
  335. .box {
  336. border:#666666 solid 1px;
  337. }
  338. </style>
  339.  
  340. </head>
  341.  
  342. <body bgcolor = "#FFFFFF">
  343.  
  344. <div align = "center">
  345. <div style = "width:300px; border: solid 1px #333333; " align = "left">
  346. <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
  347.  
  348. <div style = "margin:30px">
  349.  
  350. <form method = "post">
  351. <label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
  352. <label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
  353. <input type = "submit" value = " Submit "/><br />
  354. </form>
  355.  
  356. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php //echo $error; ?></div>
  357.  
  358. </div>
  359.  
  360. </div>
  361.  
  362. </div>
  363.  
  364. </body>
  365. </html>
  366.  
  367. <?php
  368. include("connection2.php");
  369. session_start();
  370.  
  371.  
  372.  
  373. if($_SERVER["REQUEST_METHOD"] == "POST") {
  374. // username and password sent from form
  375.  
  376. $myusername = mysqli_real_escape_string($conn,$_POST['username']);
  377. $mypassword = mysqli_real_escape_string($conn,$_POST['password']);
  378.  
  379. $sql = "SELECT id FROM login WHERE username = '".$myusername."' and password = '".$mypassword."'";
  380.  
  381. $result = $conn->query($sql);
  382.  
  383. $count = $result->num_rows;
  384.  
  385. // If result matched $myusername and $mypassword, table row must be 1 row
  386.  
  387. if($count == 1) {
  388. session_start();
  389. $_SESSION['login_user'] = $myusername;
  390.  
  391. header("location: welcome.php");
  392. }else {
  393. $error = "Your Login Name or Password is invalid";
  394. }
  395.  
  396. }
  397. ?>
  398.  
  399. <?php
  400. session_start();
  401.  
  402. if(session_destroy()) {
  403. header("Location: login.php");
  404. }
  405. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement