Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Get the data from the table and enter into database and show in table form
- <?php
- //filter_input(INPUT_POST, 'username');
- $username = $_GET["username"];
- $password = $_GET["password"];
- if(!empty($username)){
- if(!empty($password)){
- $dbhost = "localhost";
- $dbusername = "root";
- $dbpassword = "";
- $dbname = "practice";
- $connect = new mysqli ($dbhost, $dbusername, $dbpassword, $dbname);
- if(mysqli_connect_error()){
- die('('.mysqli_connect_errno().')'.mysqli_connect_error());
- }
- else{
- $value = "INSERT INTO account(Username, Password) values ($username, $password)";
- if($connect->query($value)){
- echo "New value is entered into database";
- }
- else{
- echo "Error:".$sql."<br>".$connect->error;
- }
- }
- }
- else{
- echo "Enter the password";
- die();
- }
- }
- else{
- echo "Enter the username";
- die();
- }
- $query = "SELECT * FROM account";
- echo '<table border="0" cellspacing="2" cellpadding="2">
- <tr>
- <td> <font face="Arial">Username</font> </td>
- <td> <font face="Arial">Password</font> </td>
- </tr>';
- if ($result = $connect->query($query)) {
- while ($row = $result->fetch_assoc()) {
- $field1name = $row["Username"];
- $field2name = $row["Password"];
- echo '<tr>
- <td>'.$field1name.'</td>
- <td>'.$field2name.'</td>
- </tr>';
- }
- $result->free();
- }
- ?>
- 2. Store the data into file and show as table.
- <?php
- $name = filter_input(INPUT_POST, 'username');
- $password = filter_input(INPUT_POST, 'password');
- $savestring = $name . "|" . $password. "\r";
- $fp = fopen("Format.txt", "a");
- fwrite($fp, $savestring);
- fclose($fp);
- echo "<h1>You data has been saved in a text file!</h1>";
- echo '<table border="1">';
- $file = fopen("Format.txt", "r") or die("Unable to open file!");
- while (!feof($file)){
- $data = fgets($file);
- echo "<tr><td>" . str_replace('|','</td><td>',$data) . '</td></tr>';
- }
- echo '</table>';
- fclose($file);
- ?>
- 3. sir
- <?php
- $un="day";
- $pwd="tues";
- $connection = mysqli_connect("127.0.0.1","root","","test");
- //or die("could not connect to server");
- //$db = mysqli_select_db($connection,"test");
- //or die("could not select database");
- $query ="select * from login";
- mysqli_query($connection,"insert into login values('$un','$pwd')");
- $result =mysqli_query($connection,$query);
- //or die("query failed:".mysql_error());
- While($row = mysqli_fetch_array($result))
- {
- //echo $row[0];
- //echo $row['name']," ",$row['pwd'];
- echo "Pwd:{$row['pwd']}";
- echo "<br/>";
- }
- ?>
- 4. Form
- <!DOCTYPE html>
- <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta charset="utf-8" />
- <title></title>
- <style>
- form{
- text-align: center;
- padding-top: 120px;
- font-size: 30px;
- }
- input{
- width: 250px;
- height: 30px;
- font-size: 25px;
- }
- </style>
- </head>
- <body>
- <form action="read.php" method="post">
- Username:
- <input type="text" name="username" />
- <br />
- <br />
- Password:
- <input type="Password" name="password" />
- <br />
- <br />
- <input type="submit" value="Submit" />
- </form>
- </body>
- </html>
- 5. HTML form lab 2
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>HTML FORM</title>
- <style>
- body {
- padding: 0;
- margin: 0;
- font-family: 'Times New Roman',arial, "helvetica";
- font-weight: bold;
- }
- /*sinup form*/
- input[type=text],[type=password],[type=email] {
- background-image: url("symbol.png");
- background-position: right;
- background-repeat: no-repeat;
- }
- #yeah {
- text-align: right;
- float: left;
- width: 120px;
- margin-right:5px;
- margin-left: 25px;
- }
- #fl {
- float: left;
- }
- .form-signup {
- display: block;
- width: 400px;
- min-height: 550px;
- padding: 0px 20px 10px 0px;
- background-color: #FDFF99;
- margin: 0 auto;
- margin-top: 50px;
- }
- .form-signup select {
- font-family: 'Times New Roman';
- font-weight: bold;
- font-size: medium;
- }
- p.res {
- font-family: 'Times New Roman';
- width: 420px;
- height: 30px;
- font-size: 20px;
- font-weight: bold;
- background-color: #F3C91D;
- }
- #error {
- font-weight: 500;
- font-size: 100%;
- font-weight: bold;
- color: #ff000c;
- }
- </style>
- </head>
- <body>
- <html>
- <head>
- <title>Javascript Test</title>
- <meta charset="UTF-8">
- </head>
- <body style="background-color:gainsboro">
- <div class="form-signup" id="singup">
- <center><p class="res">Registration Form</p></center>
- <form action="first.php" method="post" onsubmit="return validateMyForm();">
- <div id="fl">
- <div id="yeah">Name</div><label for="name"><input type="text" id="tbUnm" name="name" autofocus></label><br><br><br />
- <div id="yeah">Password</div><label for="passowrd"><input type="password" id="txtPassword" name="password" onkeyup="CheckPasswordStrength(this.value)" /></label><br />
- <div id="yeah"><span id="password_strength"></span></div><br><br />
- <div id="yeah">Email</div><label for="email"><input type="email" id="tbEmail" name="email"></label><br><br>
- <div id="yeah">Gender</div><label for="gender">
- <input type="radio" name="gender" value="Male" required /> Male<br />
- <div id="yeah">`</div><input type="radio" name="gender" value="female"> Female<br>
- </label><br /><br />
- <div id="yeah">Interested In</div><label for="interestedin">
- <select name="intrestedin" size="3" required>
- <option value="Designing">Designing</option>
- <option value="Coding">Coding</option>
- <option value="Analysis">Analysis</option>
- <option value="Testing">Testing</option>
- </select>
- </label><br /><br />
- <div id="yeah">Agree Terms and conditions</div><input type="checkbox" name="agree" /><br /><br /><br />
- <p id="error">
- </p>
- <center><input type="submit" style="margin-left:35px;"></center>
- </div>
- </form>
- </div>
- <script type="text/javascript">
- var error = "";
- // Email Validation
- function validateEmail(email) {
- 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,}))$/;
- return re.test(email);
- }
- // Email Validation End
- function CheckPasswordStrength(password) {
- var password_strength = document.getElementById("password_strength");
- //TextBox left blank.
- if (password.length == 0) {
- password_strength.innerHTML = "";
- return;
- }
- //Regular Expressions.
- var regex = new Array();
- regex.push("[A-Z]"); //Uppercase Alphabet.
- regex.push("[a-z]"); //Lowercase Alphabet.
- regex.push("[0-9]"); //Digit.
- regex.push("[$@$!%*#?&]"); //Special Character.
- var passed = 0;
- //Validate for each Regular Expression.
- for (var i = 0; i < regex.length; i++) {
- if (new RegExp(regex[i]).test(password)) {
- passed++;
- }
- }
- //Validate for length of Password.
- if (passed > 2 && password.length > 8) {
- passed++;
- }
- //Display status.
- var color = "";
- var strength = "";
- switch (passed) {
- case 0:
- case 1:
- strength = "Weak";
- color = "red";
- break;
- case 2:
- strength = "Good";
- color = "darkorange";
- break;
- case 3:
- case 4:
- strength = "Strong";
- color = "green";
- break;
- case 5:
- strength = "Very Strong";
- color = "darkgreen";
- break;
- }
- password_strength.innerHTML = strength;
- password_strength.style.color = color;
- }
- function validateMyForm()
- {
- if ((document.getElementById('tbUnm').value !== "") && (validateEmail(document.getElementById('tbEmail').value)) && (document.getElementById('txtPassword').value !== ""))
- {
- // location.reload();
- }
- else
- {
- error = "";
- if (document.getElementById('tbUnm').value == "")
- {
- error += "Enter your User Name<br>";
- }
- if (!validateEmail(document.getElementById('tbEmail').value))
- {
- error += "Enter Your Email<br>";
- }
- if (document.getElementById('txtPassword').value === "")
- {
- error += "Enter a Password<br>";
- }
- /*alert(error);*/
- document.getElementById('error').innerHTML = error;
- return false;
- }
- }
- </script>
- </body>
- </html>
- https://www.w3schools.com/php/func_mysqli_query.asp
- https://stackoverflow.com/questions/29867025/create-table-from-text-file-using-php
- https://www.siteground.com/tutorials/php-mysql/display-table-data/
- https://codeandcoins.blogspot.com/2017/09/how-to-connect-html-form-to-mysql.html
- 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