Guest User

Untitled

a guest
Feb 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.62 KB | None | 0 0
  1. 1. Get the data from the table and enter into database and show in table form
  2.  
  3.  
  4. <?php
  5. //filter_input(INPUT_POST, 'username');
  6. $username = $_GET["username"];
  7. $password = $_GET["password"];
  8.  
  9. if(!empty($username)){
  10. if(!empty($password)){
  11. $dbhost = "localhost";
  12. $dbusername = "root";
  13. $dbpassword = "";
  14. $dbname = "practice";
  15.  
  16. $connect = new mysqli ($dbhost, $dbusername, $dbpassword, $dbname);
  17. if(mysqli_connect_error()){
  18. die('('.mysqli_connect_errno().')'.mysqli_connect_error());
  19. }
  20. else{
  21. $value = "INSERT INTO account(Username, Password) values ($username, $password)";
  22. if($connect->query($value)){
  23. echo "New value is entered into database";
  24. }
  25. else{
  26. echo "Error:".$sql."<br>".$connect->error;
  27. }
  28. }
  29. }
  30. else{
  31. echo "Enter the password";
  32. die();
  33. }
  34. }
  35. else{
  36. echo "Enter the username";
  37. die();
  38. }
  39.  
  40. $query = "SELECT * FROM account";
  41.  
  42.  
  43. echo '<table border="0" cellspacing="2" cellpadding="2">
  44. <tr>
  45. <td> <font face="Arial">Username</font> </td>
  46. <td> <font face="Arial">Password</font> </td>
  47. </tr>';
  48.  
  49. if ($result = $connect->query($query)) {
  50. while ($row = $result->fetch_assoc()) {
  51. $field1name = $row["Username"];
  52. $field2name = $row["Password"];
  53.  
  54. echo '<tr>
  55. <td>'.$field1name.'</td>
  56. <td>'.$field2name.'</td>
  57. </tr>';
  58. }
  59. $result->free();
  60. }
  61. ?>
  62.  
  63.  
  64. 2. Store the data into file and show as table.
  65. <?php
  66. $name = filter_input(INPUT_POST, 'username');
  67. $password = filter_input(INPUT_POST, 'password');
  68. $savestring = $name . "|" . $password. "\r";
  69. $fp = fopen("Format.txt", "a");
  70. fwrite($fp, $savestring);
  71. fclose($fp);
  72. echo "<h1>You data has been saved in a text file!</h1>";
  73.  
  74. echo '<table border="1">';
  75. $file = fopen("Format.txt", "r") or die("Unable to open file!");
  76. while (!feof($file)){
  77. $data = fgets($file);
  78. echo "<tr><td>" . str_replace('|','</td><td>',$data) . '</td></tr>';
  79. }
  80. echo '</table>';
  81. fclose($file);
  82. ?>
  83.  
  84. 3. sir
  85. <?php
  86. $un="day";
  87. $pwd="tues";
  88. $connection = mysqli_connect("127.0.0.1","root","","test");
  89. //or die("could not connect to server");
  90.  
  91. //$db = mysqli_select_db($connection,"test");
  92. //or die("could not select database");
  93.  
  94. $query ="select * from login";
  95. mysqli_query($connection,"insert into login values('$un','$pwd')");
  96. $result =mysqli_query($connection,$query);
  97. //or die("query failed:".mysql_error());
  98.  
  99. While($row = mysqli_fetch_array($result))
  100. {
  101. //echo $row[0];
  102. //echo $row['name']," ",$row['pwd'];
  103. echo "Pwd:{$row['pwd']}";
  104. echo "<br/>";
  105. }
  106. ?>
  107.  
  108. 4. Form
  109. <!DOCTYPE html>
  110.  
  111. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  112. <head>
  113. <meta charset="utf-8" />
  114. <title></title>
  115. <style>
  116. form{
  117. text-align: center;
  118. padding-top: 120px;
  119. font-size: 30px;
  120. }
  121. input{
  122. width: 250px;
  123. height: 30px;
  124. font-size: 25px;
  125. }
  126. </style>
  127. </head>
  128. <body>
  129. <form action="read.php" method="post">
  130. Username:
  131. <input type="text" name="username" />
  132. <br />
  133. <br />
  134. Password:
  135. <input type="Password" name="password" />
  136. <br />
  137. <br />
  138. <input type="submit" value="Submit" />
  139. </form>
  140. </body>
  141. </html>
  142.  
  143. 5. HTML form lab 2
  144. <!DOCTYPE html>
  145. <html lang="en">
  146. <head>
  147. <meta charset="UTF-8">
  148. <title>HTML FORM</title>
  149.  
  150. <style>
  151. body {
  152. padding: 0;
  153. margin: 0;
  154. font-family: 'Times New Roman',arial, "helvetica";
  155. font-weight: bold;
  156. }
  157.  
  158.  
  159. /*sinup form*/
  160. input[type=text],[type=password],[type=email] {
  161. background-image: url("symbol.png");
  162. background-position: right;
  163. background-repeat: no-repeat;
  164. }
  165. #yeah {
  166. text-align: right;
  167. float: left;
  168. width: 120px;
  169. margin-right:5px;
  170. margin-left: 25px;
  171. }
  172.  
  173. #fl {
  174. float: left;
  175. }
  176.  
  177. .form-signup {
  178. display: block;
  179. width: 400px;
  180. min-height: 550px;
  181. padding: 0px 20px 10px 0px;
  182. background-color: #FDFF99;
  183. margin: 0 auto;
  184. margin-top: 50px;
  185. }
  186. .form-signup select {
  187. font-family: 'Times New Roman';
  188. font-weight: bold;
  189. font-size: medium;
  190. }
  191.  
  192. p.res {
  193. font-family: 'Times New Roman';
  194. width: 420px;
  195. height: 30px;
  196. font-size: 20px;
  197. font-weight: bold;
  198. background-color: #F3C91D;
  199. }
  200.  
  201. #error {
  202. font-weight: 500;
  203. font-size: 100%;
  204. font-weight: bold;
  205. color: #ff000c;
  206. }
  207.  
  208. </style>
  209.  
  210. </head>
  211. <body>
  212. <html>
  213. <head>
  214. <title>Javascript Test</title>
  215. <meta charset="UTF-8">
  216. </head>
  217. <body style="background-color:gainsboro">
  218. <div class="form-signup" id="singup">
  219. <center><p class="res">Registration Form</p></center>
  220. <form action="first.php" method="post" onsubmit="return validateMyForm();">
  221. <div id="fl">
  222.  
  223. <div id="yeah">Name</div><label for="name"><input type="text" id="tbUnm" name="name" autofocus></label><br><br><br />
  224.  
  225. <div id="yeah">Password</div><label for="passowrd"><input type="password" id="txtPassword" name="password" onkeyup="CheckPasswordStrength(this.value)" /></label><br />
  226. <div id="yeah"><span id="password_strength"></span></div><br><br />
  227.  
  228. <div id="yeah">Email</div><label for="email"><input type="email" id="tbEmail" name="email"></label><br><br>
  229.  
  230. <div id="yeah">Gender</div><label for="gender">
  231. <input type="radio" name="gender" value="Male" required /> Male<br />
  232. <div id="yeah">`</div><input type="radio" name="gender" value="female"> Female<br>
  233. </label><br /><br />
  234.  
  235. <div id="yeah">Interested In</div><label for="interestedin">
  236. <select name="intrestedin" size="3" required>
  237. <option value="Designing">Designing</option>
  238. <option value="Coding">Coding</option>
  239. <option value="Analysis">Analysis</option>
  240. <option value="Testing">Testing</option>
  241. </select>
  242. </label><br /><br />
  243.  
  244. <div id="yeah">Agree Terms and conditions</div><input type="checkbox" name="agree" /><br /><br /><br />
  245.  
  246. <p id="error">
  247. </p>
  248.  
  249. <center><input type="submit" style="margin-left:35px;"></center>
  250.  
  251. </div>
  252. </form>
  253. </div>
  254.  
  255. <script type="text/javascript">
  256. var error = "";
  257. // Email Validation
  258. function validateEmail(email) {
  259. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  260. return re.test(email);
  261. }
  262. // Email Validation End
  263.  
  264. function CheckPasswordStrength(password) {
  265. var password_strength = document.getElementById("password_strength");
  266.  
  267. //TextBox left blank.
  268. if (password.length == 0) {
  269. password_strength.innerHTML = "";
  270. return;
  271. }
  272.  
  273. //Regular Expressions.
  274. var regex = new Array();
  275. regex.push("[A-Z]"); //Uppercase Alphabet.
  276. regex.push("[a-z]"); //Lowercase Alphabet.
  277. regex.push("[0-9]"); //Digit.
  278. regex.push("[$@$!%*#?&]"); //Special Character.
  279.  
  280. var passed = 0;
  281.  
  282. //Validate for each Regular Expression.
  283. for (var i = 0; i < regex.length; i++) {
  284. if (new RegExp(regex[i]).test(password)) {
  285. passed++;
  286. }
  287. }
  288.  
  289. //Validate for length of Password.
  290. if (passed > 2 && password.length > 8) {
  291. passed++;
  292. }
  293.  
  294. //Display status.
  295. var color = "";
  296. var strength = "";
  297. switch (passed) {
  298. case 0:
  299. case 1:
  300. strength = "Weak";
  301. color = "red";
  302. break;
  303. case 2:
  304. strength = "Good";
  305. color = "darkorange";
  306. break;
  307. case 3:
  308. case 4:
  309. strength = "Strong";
  310. color = "green";
  311. break;
  312. case 5:
  313. strength = "Very Strong";
  314. color = "darkgreen";
  315. break;
  316. }
  317. password_strength.innerHTML = strength;
  318. password_strength.style.color = color;
  319. }
  320.  
  321.  
  322. function validateMyForm()
  323. {
  324. if ((document.getElementById('tbUnm').value !== "") && (validateEmail(document.getElementById('tbEmail').value)) && (document.getElementById('txtPassword').value !== ""))
  325. {
  326. // location.reload();
  327. }
  328. else
  329. {
  330. error = "";
  331. if (document.getElementById('tbUnm').value == "")
  332. {
  333. error += "Enter your User Name<br>";
  334. }
  335. if (!validateEmail(document.getElementById('tbEmail').value))
  336. {
  337. error += "Enter Your Email<br>";
  338. }
  339. if (document.getElementById('txtPassword').value === "")
  340. {
  341. error += "Enter a Password<br>";
  342. }
  343.  
  344. /*alert(error);*/
  345. document.getElementById('error').innerHTML = error;
  346.  
  347. return false;
  348. }
  349. }
  350. </script>
  351. </body>
  352. </html>
  353.  
  354.  
  355.  
  356. https://www.w3schools.com/php/func_mysqli_query.asp
  357. https://stackoverflow.com/questions/29867025/create-table-from-text-file-using-php
  358. https://www.siteground.com/tutorials/php-mysql/display-table-data/
  359. https://codeandcoins.blogspot.com/2017/09/how-to-connect-html-form-to-mysql.html
  360. https://www.codeandcourse.com/2017/09/how-to-connect-html-form-to-mysql-database-using-php-in-4-minutes/
Add Comment
Please, Sign In to add comment