cba_guru

php

Dec 2nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. dbconn.php
  2. <?php
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "sca";
  7. $conn = new mysqli($servername, $username, $password, $dbname);
  8. if ($conn->connect_error)
  9. {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12. ?>
  13. ----------------------------------------------
  14. Index.php
  15. <html>
  16. <head>
  17. <title>Couse List</title>
  18. </head>
  19. <body bgcolor="lightgreen">
  20. <center><a href="new_course.php">New Course</a></center>
  21. <table align="center" border="1" cellspacing="2" cellpadding="2">
  22. <caption><h2>Course List</h2></caption>
  23. <tr>
  24. <td>S.L. No.</td>
  25. <td>Courses Name</td>
  26. <td>Delete</td>
  27. </tr>
  28. <?php
  29. error_reporting(0);
  30. include("dbconn.php");
  31. $res = mysqli_query ($conn,"Select * from courses");
  32. while($row=mysqli_fetch_array($res))
  33. {
  34. ?>
  35. <tr>
  36. <td><?php echo $row['id'];?></td>
  37. <td><?php echo $row['name'];?></td>
  38. <td><a href="delete_course.php?id=<?php echo $row['id']?>">Delete</a></td>
  39. </tr>
  40. <? } ?>
  41. </table>
  42. </body>
  43. </html>
  44. ----------------------------------------------
  45. new_course.php
  46. <html>
  47. <head>
  48. <title>Add New Course</title>
  49. </head>
  50. <body bgcolor="#0033FF">
  51. <center><a href="index.php">Course List</a></center>
  52. <center>
  53. <form method="post" action="action.php">
  54. <table border="1" cellpadding="2" cellspacing="2">
  55. <caption><marquee><h2>Add New Course</h2></marquee></caption>
  56. <tr>
  57. <th>Course Name</th>
  58. <td><input type="text" name="name"/> </td>
  59. </tr>
  60. </table>
  61. <br><br>
  62. <input type="submit" name="submit" value="SUBMIT">
  63. <input type="reset" name="reset" value="RESET">
  64. </form>
  65. </center>
  66. </body>
  67. </html>
  68. ----------------------------------------------
  69. action.php
  70. <?php
  71. error_reporting(0);
  72. include("dbconn.php");
  73. $name = $_POST['name'];
  74. $sql = "INSERT INTO courses(name) VALUES('$name')";
  75. mysqli_query($conn, $sql);
  76. echo "Inserted Successfully<br/>";
  77. header("location:index.php");
  78. ?>
  79. ----------------------------------------------
  80. delete_course.php
  81. <?php
  82. error_reporting(0);
  83. include("dbconn.php");
  84. $id = $_REQUEST['id'];
  85. mysqli_query($conn,"Delete from courses where id='$id'");
  86. header("location:index.php");
  87. ?>
  88. ----------------------------------------------
  89. update_user.php
  90. <?php
  91. error_reporting(0);
  92. include("dbconn.php");
  93. $u_id = $_POST['u_id'];
  94. $u_name = $_POST['u_name'];
  95. $u_email = $_POST['u_email'];
  96. $u_ph = $_POST['u_ph'];
  97. $u_address = $_POST['u_address'];
  98.  
  99. $sql = "UPDATE users SET u_name = '$u_name', u_email = '$u_email', u_ph = '$u_ph', u_address = '$u_address' WHERE u_id = '$u_id'";
  100.  
  101. //mysql_query($sql);
  102. mysqli_query($conn,$sql);
  103. header("location:user_list.php");
  104.  
  105. ?>
  106. ----------------------------------------------
  107. edit_user.php
  108. <?php
  109. error_reporting(0);
  110. include("dbconn.php");
  111. $u_id = $_REQUEST['id'];
  112. $sql = "Select * from users where u_id = '$u_id'";
  113. //$res = mysql_query($sql);
  114. $res = mysqli_query($conn,$sql);
  115. //$row = mysql_fetch_array($res);
  116. $row = mysqli_fetch_array($res);
  117. ?>
  118.  
  119. <html>
  120. <body>
  121. <form method="POST" action="update_user.php">
  122. <table align="center">
  123. <caption><h2>Update User</h2></caption>
  124. <tr>
  125. <td>User Name</td>
  126. <td><input type="text" name="u_name" value="<?php echo $row['u_name'];?>"></td>
  127. </tr>
  128. <tr>
  129. <td>E-mail</td>
  130. <td><input type="text" name="u_email" value="<?php echo $row['u_email'];?>"></td>
  131. </tr>
  132. <tr>
  133. <td>Phone</td>
  134. <td><input type="text" name="u_ph" value="<?php echo $row['u_ph'];?>"></td>
  135. </tr>
  136. <tr>
  137. <td>Address</td>
  138. <td>
  139. <input type="text" name="u_address" value="<?php echo $row['u_address'];?>">
  140. <input type="hidden" name="u_id" value="<?php echo $row['u_id'];?>">
  141. </td>
  142. </tr>
  143. <tr>
  144. <td colspan="2"><button>Update</button></td>
  145. </tr>
  146. </table>
  147.  
  148. </form>
  149. </body>
  150. </html>
  151. -----------------------------------------
  152. Index.php
  153. <html>
  154. <body bgcolor="#6699FF">
  155. <center>
  156. <table>
  157. <caption><marquee>Sceond CAP</marquee></caption>
  158. <br>
  159. <br>
  160. <tr bgcolor="#00FF66" ><br>
  161. <td><a href='string.php'> String Reverse</a></td>
  162. <td><a href='function.php'> Gobal Variables<a/></td>
  163. </tr>
  164. </table>
  165. </center>
  166. </body>
  167. </html>
  168. -----------------------------------------
  169. string.php
  170. <html>
  171. <body>
  172. <center>
  173. The String is Hello
  174. <br>
  175. <br>
  176. Using strlen Function
  177. <br>
  178. <?php
  179. $string = 'Hello';
  180. for ($i=0; $i < strlen($string); $i++)
  181. {
  182. printf("The %dth character is %s<br>",
  183. $i, $string{$i});
  184. }
  185. ?>
  186. <br>
  187. <br>
  188. Using strrrev Function<br>
  189. <?php
  190. $reverse=strrev($string);
  191. for($i=0;$i<strlen($string);$i++)
  192. {
  193. echo "the ",$i,"th character is ",substr($reverse,$i,1),"<br>";
  194. }
  195. ?>
  196. <br>
  197. <a href="index.php">Back</a>
  198. </center>
  199. </body>
  200. </html>
  201. -----------------------------------------
  202. function.php
  203. <html>
  204. <body>
  205. <center>
  206. <br>
  207. <br>
  208. <br>
  209. <?php
  210. $a = 3;
  211. echo 'Initially the value of $a is 3<br>';
  212. function tahsin()
  213. {
  214. global $a;
  215. $a += 2;
  216. }
  217. tahsin();
  218. echo 'After using the global functionality, the value of $a is ' .$a;
  219. ?>
  220. <br>
  221. <br>
  222. <a href="index.php">Back</a>
  223. </center>
  224. </body>
  225. </html>
  226. -----------------------------------------
  227. PHP Operators:
  228. Arithmetic operators
  229. Assignment operators
  230. Comparison operators
  231. Increment/Decrement operators
  232. Logical operators
  233. String operators
  234. Array operators
  235. ----------------------------------------
  236. PHP - The if...elseif....else Statement
  237. <?php
  238. $t = date("H");
  239.  
  240. if ($t < "10") {
  241. echo "Have a good morning!";
  242. } elseif ($t < "20") {
  243. echo "Have a good day!";
  244. } else {
  245. echo "Have a good night!";
  246. }
  247. ?>
  248. --------------------------------------
  249. PHP switch Statement
  250. <?php
  251. $favcolor = "red";
  252.  
  253. switch ($favcolor) {
  254. case "red":
  255. echo "Your favorite color is red!";
  256. break;
  257. case "blue":
  258. echo "Your favorite color is blue!";
  259. break;
  260. case "green":
  261. echo "Your favorite color is green!";
  262. break;
  263. default:
  264. echo "Your favorite color is neither red, blue, nor green!";
  265. }
  266. ?>
  267. ---------------------------------------
  268. PHP while Loop
  269. <?php
  270. $x = 1;
  271.  
  272. while($x <= 5) {
  273. echo "The number is: $x <br>";
  274. $x++;
  275. }
  276. ?>
  277. -------------------------------------
  278. PHP foreach Loop
  279. <?php
  280. for ($x = 0; $x <= 10; $x++) {
  281. echo "The number is: $x <br>";
  282. }
  283. ?>
  284. -----------------------------------
  285. Arrays
  286. <?php
  287. $cars = array("Volvo", "BMW", "Toyota");
  288. echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
  289. ?>
  290. ------------------------------
  291. Cookies
  292. <?php
  293. $cookie_name = "user";
  294. $cookie_value = "John Doe";
  295. setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
  296. ?>
  297. <html>
  298. <body>
  299.  
  300. <?php
  301. if(!isset($_COOKIE[$cookie_name])) {
  302. echo "Cookie named '" . $cookie_name . "' is not set!";
  303. } else {
  304. echo "Cookie '" . $cookie_name . "' is set!<br>";
  305. echo "Value is: " . $_COOKIE[$cookie_name];
  306. }
  307. ?>
  308.  
  309. </body>
  310. </html>
  311. --------------------------------
  312. session
  313. <?php
  314. // Start the session
  315. session_start();
  316. ?>
  317. <!DOCTYPE html>
  318. <html>
  319. <body>
  320.  
  321. <?php
  322. // Set session variables
  323. $_SESSION["favcolor"] = "green";
  324. $_SESSION["favanimal"] = "cat";
  325. echo "Session variables are set.";
  326. ?>
  327.  
  328. </body>
  329. </html>
  330. -----------------------------
  331. date time
  332. <?php
  333. echo "Today is " . date("Y/m/d") . "<br>";
  334. echo "Today is " . date("Y.m.d") . "<br>";
  335. echo "Today is " . date("Y-m-d") . "<br>";
  336. echo "Today is " . date("l");
  337. ?>
  338. ---------------------------
  339. switch
  340. <?php
  341. $favcolor="pink";
  342. switch($favcolor){
  343. case"red":
  344. echo"Your favorite coloris red!";
  345. break;
  346.  
  347. case"pink":
  348. echo"Your favorite coloris pink!";
  349. break;
  350.  
  351. case"green":
  352. echo"Your favorite coloris green!";
  353. break;
  354.  
  355. default:
  356. echo"Your favorite coloris neither red, blue, nor green!";}
  357.  
  358. ?>
  359. ------------------------------------
  360. Image eclipse
  361. <?php
  362. $image = imagecreatetruecolor(150, 150);
  363. //imagecreatetruecolor(width, height)
  364. $white = imagecolorallocate($image, 255, 255, 255);
  365. $text_color = imagecolorallocate($image,0,255,0);
  366. imagefilledrectangle($image, 0, 0, 150, 150, $white);
  367.  
  368.  
  369. $color = imagecolorallocatealpha($image, 0, 0, 255, 30);
  370. //imagecolorallocatealpha(image, red, green, blue, alpha)
  371. //The alpha value is between 0 (opaque) and 127 (transparent).
  372. imagefilledellipse($image, 75, 75, 80, 63, $color);
  373. imagestring($image,5,10,110,"Eclipse Created",$text_color);
  374. header("Content-Type: image/png");
  375. imagepng($image);
  376. ?>
  377. ----------------------------------
  378.  
  379. <?php
  380. $image = imagecreate(200, 200);
  381. $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
  382. $black = imagecolorallocate($image, 0x00, 0x00, 0x00);
  383. $color = imagecolorallocate($image, 255,0,255);
  384. $color1 = imagecolorallocate($image,0,0,255);
  385.  
  386.  
  387. $color2 = imagecolorallocate($image,255,0,0);
  388. //imagestring(image, font_id, x, y, text, color);
  389. imagestring($image, 1, 10, 10, "LPU Practical", $black);
  390. imagestring($image, 2, 10, 30, "Happy", $black);
  391. imagestring($image, 3, 10, 50, "Childrens", $color);
  392. imagestring($image, 4, 10, 70, "Day", $color1);
  393. imagestring($image, 5, 10, 90, "Have a good day", $color2);
  394. header("Content-Type: image/png");
  395. imagepng($image);
  396. ?>
  397. ----------------------------------------
  398.  
  399. <?php
  400. $image = imagecreatetruecolor(150, 150);
  401. $white = imagecolorallocate($image, 255, 255, 255);
  402. imagefilledrectangle($image, 0, 0, 150, 150, $white);
  403. $red = imagecolorallocatealpha($image, 255, 50, 0, 36);
  404. //imagecolorallocatealpha(image, red, green, blue, alpha)
  405.  
  406. imagefilledellipse($image, 75, 75, 80, 50, $red);
  407. $gray = imagecolorallocatealpha($image, 70, 70, 70, 5);
  408. //imagecolorallocatealpha(image, red, green, blue, alpha)
  409. imagefilledrectangle($image, 60, 60, 120, 120, $gray);
  410. header("Content-Type: image/png");
  411. imagepng($image);
  412. ?>
  413. -----------------------------------------
  414.  
  415. <?php
  416. $image = imagecreate(200, 200);
  417. $white = imagecolorallocate($image, 255, 255, 255);
  418. //$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
  419. $black = imagecolorallocate($image, 0, 0, 0);
  420. //$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
  421. imagefilledrectangle($image, 80, 50, 500, 300, $black);
  422. header("Content-Type: image/png");
  423. imagepng($image);
  424. ?>
  425. --------------------------------------
Add Comment
Please, Sign In to add comment