Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.80 KB | None | 0 0
  1. ///classes .....................
  2. <?php
  3. class saveusers
  4. {
  5. protected $name;
  6. protected $message;
  7. protected $password;
  8. protected $id;
  9.  
  10.  
  11. public function saveuUserInfo()
  12. {
  13. $name =$this->getName();
  14. $message=$this->getMessage();
  15. $password=$this->getPassword();
  16. $connect= new connect();
  17. $mysql=$connect->getconnection();
  18. $query = "insert into users(name,message,password) values('$name','$message','$password')";
  19. //die($query);
  20. mysqli_query( $mysql,$query);
  21. }
  22. public function updateuser()
  23. {
  24. $name =$this->getName();
  25. $message=$this->getMessage();
  26. $password=$this->getPassword();
  27. $connect= new connect();
  28. $mysql=$connect->getconnection();
  29. $query = "update users set name='$name',message='$message',password='$password' where id=".$this->getId();
  30. // die($query);
  31. mysqli_query( $mysql,$query);
  32. }
  33. public function deletedata()
  34. {
  35. $connect= new connect();
  36. $mysql=$connect->getconnection();
  37. $query="delete from users where id=".$this->getId();
  38. mysqli_query($mysql,$query);
  39. }
  40.  
  41. /**
  42. * @return mixed
  43. */
  44. public function getId()
  45. {
  46. return $this->id;
  47. }
  48.  
  49. /**
  50. * @param mixed $id
  51. */
  52. public function setId($id)
  53. {
  54. $this->id = $id;
  55. }
  56.  
  57. /**
  58. * @return mixed
  59. */
  60. public function getName()
  61. {
  62. return $this->name;
  63. }
  64.  
  65. /**
  66. * @param mixed $name
  67. */
  68. public function setName($name)
  69. {
  70. $this->name = $name;
  71. }
  72.  
  73. /**
  74. * @return mixed
  75. */
  76. public function getMessage()
  77. {
  78. return $this->message;
  79. }
  80.  
  81. /**
  82. * @param mixed $message
  83. */
  84. public function setMessage($message)
  85. {
  86. $this->message = $message;
  87. }
  88.  
  89. /**
  90. * @return mixed
  91. */
  92. public function getPassword()
  93. {
  94. return $this->password;
  95. }
  96.  
  97. /**
  98. * @param mixed $password
  99. */
  100. public function setPassword($password)
  101. {
  102. $this->password = $password;
  103. }
  104. }
  105.  
  106. next class.......................
  107. <?php
  108.  
  109. /**
  110. * Created by PhpStorm.
  111. * User: Rabin
  112. * Date: 1/17/2017
  113. * Time: 7:36 PM
  114. */
  115. class showusers extends connect
  116. {
  117. protected $table;
  118. protected $id;
  119. public function getdata()
  120. {
  121. $connect=new self();
  122. $mysql=$connect->getconnection();
  123. $query='select * from '.$this->getTable();
  124. $result= mysqli_query($mysql,$query);
  125. $users=[];
  126. while ($row=mysqli_fetch_assoc($result))
  127. {
  128. $data=new saveusers();
  129. $data->setName($row['name']);
  130. $data->setPassword($row['password']);
  131. $data->setMessage($row['message']);
  132. $data->setId($row['id']);
  133. $users[]=$data;
  134. }
  135. //var_dump($data);
  136. return $users;
  137. }
  138. public function showuserinfo()
  139. {
  140. $connect=new connect();
  141. $mysql=$connect->getconnection();
  142. $query="select * from users where id=".$this->getId();
  143. $result=mysqli_query($mysql,$query);
  144. $row=mysqli_fetch_assoc($result);
  145. $data=new saveusers();
  146. $data->setName($row['name']);
  147. $data->setPassword($row['password']);
  148. $data->setMessage($row['message']);
  149. $data->setId($row['id']);
  150. // echo "<pre>";
  151. // var_dump($data);
  152. // die;
  153. return $data;
  154. }
  155.  
  156. /**
  157. * @return mixed
  158. */
  159. public function getId()
  160. {
  161. return $this->id;
  162. }
  163.  
  164. /**
  165. * @param mixed $id
  166. */
  167. public function setId($id)
  168. {
  169. $this->id = $id;
  170. }
  171.  
  172. public function getTable()
  173. {
  174. return $this->table;
  175. }
  176.  
  177. /**
  178. * @param mixed $table
  179. */
  180. public function setTable($table)
  181. {
  182. $this->table = $table;
  183. }
  184.  
  185. }
  186.  
  187. next classs........................... for connection
  188.  
  189. <?php
  190.  
  191. class connect
  192. {
  193. protected $host;
  194. protected $user;
  195. protected $password;
  196. protected $database;
  197.  
  198. public function getconnection()
  199. {
  200. $this->setHost('localhost');
  201. $this->setUser('root');
  202. $this->setPassword('');
  203. $this->setDatabase('leapfrog');
  204. return mysqli_connect($this->host,$this->user,$this->password,$this->database);
  205. }
  206.  
  207. /**
  208. * @return mixed
  209. */
  210. public function getHost()
  211. {
  212. return $this->host;
  213. }
  214.  
  215. /**
  216. * @param mixed $host
  217. */
  218. public function setHost($host)
  219. {
  220. $this->host = $host;
  221. }
  222.  
  223. /**
  224. * @return mixed
  225. */
  226. public function getUser()
  227. {
  228. return $this->user;
  229. }
  230.  
  231. /**
  232. * @param mixed $user
  233. */
  234. public function setUser($user)
  235. {
  236. $this->user = $user;
  237. }
  238.  
  239. /**
  240. * @return mixed
  241. */
  242. public function getPassword()
  243. {
  244. return $this->password;
  245. }
  246.  
  247. /**
  248. * @param mixed $password
  249. */
  250. public function setPassword($password)
  251. {
  252. $this->password = $password;
  253. }
  254.  
  255. /**
  256. * @return mixed
  257. */
  258. public function getDatabase()
  259. {
  260. return $this->database;
  261. }
  262.  
  263. /**
  264. * @param mixed $database
  265. */
  266. public function setDatabase($database)
  267. {
  268. $this->database = $database;
  269. }
  270. }
  271.  
  272.  
  273. .................for saving and listing data ..........................
  274.  
  275. <html>
  276. <head>
  277. <title> display </title>
  278. <link rel="stylesheet" href="css/bootstrap.css">
  279. </head>
  280. <body>
  281. <?php
  282. include 'vendor/autoload.php';
  283. ..............save data.................
  284. if (isset($_POST['save'])) {
  285. $user = new saveusers();
  286. $user->setName($_POST['name']);
  287. $user->setPassword($_POST['password']);
  288. $user->setMessage($_POST['message']);
  289. $user->saveuUserInfo();
  290. }
  291. ..............show data............
  292.  
  293. $show=new showusers();
  294. $show->setTable('users');
  295. $result=$show->getdata();
  296. //echo "<pre>";
  297. //var_dump($result);
  298. //die;
  299. //echo "<pre>";
  300. //var_dump($result);
  301. ?>
  302. <div class="container">
  303. <table class="table-condensed table-bordered table-hover">
  304. <tr>
  305. <td>Name</td>
  306. <td>Password</td>
  307. <td>Message</td>
  308. </tr>
  309. <?php foreach ($result as $data ){ ?>
  310. <tr>
  311. <td><?php echo $data->getname(); ?></td>
  312. <td><?php echo $data->getpassword();?></td>
  313. <td><?php echo $data->getMessage();?></td>
  314. <td>
  315. <div class="form-group" >
  316. <a href="delete.php?id=<?php echo $data->getid();?>" class="btn btn-info">Delete</a>
  317. </div>
  318. </td><td>
  319. <div class="form-group" >
  320. <a href="update.php?id=<?php echo $data->getid();?>" class="btn btn-info"> Update</a>
  321. </div>
  322. </td>
  323. <?php } ?>
  324. </tr>
  325. </table>
  326. </div>
  327. <?php
  328. ?>
  329. </body>
  330. </html>
  331.  
  332. ......................for deleting data.......................
  333.  
  334. <?php
  335. include 'vendor/autoload.php';
  336. $user=new saveusers();
  337. $user->setid($_GET['id']);
  338. $user->deletedata();
  339. header('location:save.php');
  340.  
  341. ...............for updating data ..............................
  342. ...............showing data for update........
  343. <?php
  344. include 'vendor/autoload.php';
  345. $show=new showusers();
  346. $show->setId($_GET['id']);
  347. $row=$show->showuserinfo();
  348. //echo "<pre>";
  349. //var_dump($row);
  350. //die;
  351. if (!empty($row)){
  352. ?>
  353. <html>
  354. <head>
  355. <title>Form</title>
  356. <link rel="stylesheet" href="css/bootstrap.css">
  357. </head>
  358. <body>
  359. <div class="container">
  360. <div class="row">
  361. <h1>Form</h1>
  362. <form action="saveupdate.php" class="form" method="get">
  363. <div class="form-group">
  364. <label for="name">Name</label>
  365. <input type="text" name="name"class="form-control" value="<?php echo $row->getName(); ?>">
  366. </div>
  367. <div class="form-group">
  368. <label for="password">Password</label>
  369. <input type="password" name="password" class="form-control" value="<?php echo $row->getPassword();?>">
  370. </div>
  371. <div class="form-group">
  372. <label for="message">Message</label>
  373. <textarea name="message" id="" cols="30" rows="10" class="form-control"><?php echo $row->getMessage(); ?></textarea>
  374. </div>
  375. <div class="form-group" >
  376. <input name="id" type="hidden" value="<?php echo $row->getId(); ?>"/>
  377. <button class="btn btn-info" name="update" >Update</button>
  378. </div>
  379. </form>
  380. </div>
  381. </div>
  382. </body>
  383. </html>
  384. <?php } ?>
  385.  
  386. ....................update ...............
  387.  
  388. <?php
  389. include 'vendor/autoload.php';
  390. $update=new saveusers();
  391. $update->setId($_GET['id']);
  392. $update->setName($_GET['name']);
  393. $update->setMessage($_GET['message']);
  394. $update->setPassword($_GET['password']);
  395. $update->updateuser();
  396. header('location:save.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement