Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FORM CREATION
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "Database";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (mysqli_connect_errno()) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $fn=$_POST['firstname'];
- $ln=$_POST['lastname'];
- $dob=$_POST['dob'];
- $sql = "insert into records(firstname,lastname,dob) values('$fn','$ln','$dob');";
- $r=mysqli_query($conn,$sql);
- if(!$r)
- {die(mysqli_error($conn));
- }
- else
- {echo "Record created";}
- $conn->close();
- ?>
- EDIT REDIRECTION
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "Database";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (mysqli_connect_errno()) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $fn=$_POST['firstname'];
- $sql = "select * from records where firstname='$fn';";
- $r=mysqli_query($conn,$sql);
- if(!$r)
- {die(mysqli_error($conn));
- }
- else
- {
- echo" <form action='edit1.php' method='post'>";
- while( $row=mysqli_fetch_array($r))
- {
- echo"<input type='text' value=$row[1] name='firstname'>";
- echo"<input type='text' value=$row[2] name='lastname'>";
- echo"<input type='text' value=$row[3] name='dob'>
- <input type='submit'>
- </form>";
- }
- }
- $conn->close();
- ?>
- EDIT CODE
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "Database";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (mysqli_connect_errno()) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $fn=$_POST['firstname'];
- $ln=$_POST['lastname'];
- $dob=$_POST['dob'];
- $sql = "update records set lastname='$ln', dob='$dob' where firstname='$fn';";
- $r=mysqli_query($conn,$sql);
- if(!$r)
- {die(mysqli_error($conn));
- }
- else
- {echo "Record edited";}
- $conn->close();
- ?>
- FORM-HTML
- <html>
- <head>
- <title>Form to fill the database Records</title>
- <style>
- .n
- {
- float:left;
- margin-left:10%;
- margin-right:10%;
- width:30%;
- color:red;
- background-color:yellow;
- }
- .r
- {
- float: left;
- width:30%;
- margin-left:10%
- margin-right:10%
- color:blue;
- background-color:yellow;
- }
- .a{background-color:yellow;
- }
- table td:first-child:hover{
- padding : 10%;
- color:blue;
- }
- </style>
- </head>
- <body style="background-color:"yellow">
- <h1><b>Please input the respective fields</b></h1>
- <br><br>
- <div class="a">
- <form name="myform" action="form.php" method="post" >
- <div class="n"> Enter your first name</div>
- <div class="r"><input type="text" name="firstname" required></div>
- <br>
- <div class="n"> Enter your last name</div>
- <div class="r"><input type="text" name="lastname" required></div>
- <br>
- <div class="n"> Enter your date of birth</div>
- <div class="r"> <input type="text" name="dob" required></div>
- <br>
- <div class="n"> Click here to submit your details</div>
- <div class="r"> <input type="submit" onclick="window.alert('Are you sure you want to submit?')"></div>
- <br>
- </form>
- </div>
- <a href="edit.html">Click here to edit details</a>
- <form>
- <table>
- <tr>
- <td width=50%>
- First name</td>
- <td>
- <input type='text'>
- </td>
- </tr>
- <tr>
- <td>
- baap
- </td>
- <td>
- bera
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- EDIT HTML
- <html>
- <head>
- <title>Form to fill the database Records</title>
- </head>
- <body style="background-color:"yellow">
- <h1><b>Please input the respective fields</b></h1>
- <br><br>
- <div class="a">
- <form name="myform" action="edit.php" method="post" >
- <div class="n"> Enter the first name for which you want to edit details</div>
- <div class="r"><input type="text" name="firstname" required></div>
- <div class="n"> Click here to submit your details</div>
- <div class="r"> <input type="submit"></div>
- <br>
- </form>
- </div>
- </html>
- var x=document.getElementsByClassName("hero");
- for(i=0;i<x.length;i++)
- {
- x[i].style.backgroundColor="red";
- }
- EVENT-onchange()-active validation
- EXERCISE 7: Course Information Webpage
- HTML Code:
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- .labels {
- width: 46%;
- float: left;
- text-align: right;
- border: 2px solid green;
- margin: 10px 1%;
- }
- .inputs {
- width: 46%;
- float: left;
- text-align: left;
- margin: 10px 1%;
- }
- .bodydiv {
- background-color: powderblue;
- border: 2px solid green;
- width: 60%;
- margin: 0 auto;
- border-radius: 25px;
- }
- .lines {
- clear: both; }
- .input-box {
- width: 100%;
- border: 2px solid green;
- }
- select {
- border: 2px solid green;
- }
- textarea {
- border: 2px solid green;
- height: 80px;
- }
- </style>
- </head>
- <body>
- <div class="bodydiv">
- <form>
- <div class="lines" style="margin: 20px auto;text-align: center;">
- <h2 style= font-family: sans-serif;">Course Information</h2>
- </div>
- <div class="lines">
- <div class="labels">Name:</div>
- <div class="inputs"><input class="input-box" type="text" name="name"></div>
- </div>
- <div class="lines">
- <div class="labels">Email:</div>
- <div class="inputs"><input class="input-box" type="email" name="email"></div>
- </div>
- <div class="lines">
- <div class="labels">Gender:</div><div class="inputs">
- <select class="input-box" name="gender">
- <option value="male">
- Male
- </option>
- <option value="female"> Female </option>
- </select></div> </div>
- <div class="lines">
- <div class="labels">Date of Birth:</div>
- <div class="inputs"><input class="input-box" type="date" name="dob"></div>
- </div>
- <div class="lines">
- <div class="labels">Course Name:</div><div class="inputs"><input class="input-box" type="text" name="cname"></div>
- </div>
- <div class="lines">
- <div class="labels">Course Code:</div><div class="inputs"><input class="input-box" type="text" name="ccode"></div>
- </div>
- <div class="lines">
- <div class="labels">Slot:</div><div class="inputs">
- <select class="input-box">
- <option value="5_6">
- L33+L34
- </option>
- </select></div>
- </div>
- <div class="lines">
- <div class="labels">Mobile Number:</div><div class="inputs"><input class="input-box" type="number" name="mno"></div>
- </div>
- <div style="width: 96%" class="lines">
- <textarea class="input-box" style="margin: 1%;" placeholder="Remarks"></textarea>
- </div>
- <div class="lines" style="text-align: center;">
- <input type="Submit" name="Submit" value="Submit" style="margin-bottom: 20px;width: 250px;background:green;height: 40px; color: white; box-shadow: none;">
- </div>
- </form>
- </div>
- </body>
- </html>
- EXERCISE 8: Form Validation without Javascript
- HTML Code:
- <!DOCTYPE html>
- <html>
- <head>
- <title>Form Validation Without Javascript</title>
- <style>
- body{
- background: grey;
- }
- form{
- width: 50%;
- margin-left: auto;
- margin-right: auto;
- background: white;
- border-radius: 20px;
- }
- h1{
- color: white;
- background: red;
- border-radius: 20px 20px 0px 0px;
- padding: 2%;
- text-align: center;
- }
- .form {
- padding: 2%;
- }
- input{
- margin-left: auto;
- margin-right: auto;
- width: 80%;
- display: block;
- outline-color: red;
- background-image: url("/home/likewise-open/VITUNIVERSITY/Documents/icons/symbol.png");
- background-repeat: no-repeat;
- background-position: right;
- width: 100%;
- padding: 12px 20px;
- margin: 8px 0;
- box-sizing: border-box;
- }
- input:focus{
- padding: 2%;
- display: block;
- outline-color: red;
- background-image: url("/home/likewise-open/VITUNIVERSITY/14bce0735/Documents/icons/invalid.png");
- background-repeat: no-repeat;
- background-position: right;
- }
- input:valid{
- display: block;
- outline-color: green;
- background-image: url("/home/likewise-open/VITUNIVERSITY//Documents/icons/valid.png");
- background-repeat: no-repeat;
- background-position: right;
- }
- input[type=submit]:hover {
- background-color: darkred;
- }
- input[type=submit] {
- width: 100%;
- background-color: red;
- color: white;
- padding: 14px 20px;
- margin: 8px 0;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- background-image: none;
- }
- </style>
- </head>
- <body>
- <form action="action_page.php">
- <h1>HTML and CSS Form Validation</h1>
- <div class="form">
- <input type="text" name="username" placeholder="Username"
- pattern=".{7,}" required>
- <input type="password" name="pw" placeholder="Password"
- pattern=".{6,}" required>
- <input type="email" name="email" placeholder="Email ID"
- pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" required>
- <input type="text" name="phoneNumber" pattern="[0-9]{10}"
- placeholder="Mobile Number" required>
- <input type="text" name="WebAddress" placeholder="Web Address"
- pattern="https?://.+" required>
- <div class="form">
- <input type="submit" >
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment