Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Experiment 2.

(20BCA1331

Student Name: smriti UID: 20BCA1331

Branch: BCA Section/Group: 4-B

Semester: 5th Date of Performance: 30.10.22

Subject Name: Web technology lab Subject Code: 20CAP-315

1. Aim/Overview of the practical:


Creating Form and Connecting database.

2. Task to be done:
Create the database connection between login and registration form and
database using PHP and MySQL.

3. Concept used:
The GET method refers to a HyperText Transfer Protocol (HTTP) method
that is applied while requesting information from a particular source.

POST is used to send data to a server to create/update a resource. Some


notes on POST requests:

MySQL is a tool used to manage databases and servers,

Admin is the role with the highest level of access to your website.

4. Steps/Commands involved to perform practical:


Code
Database Connection

<?php

$server = "localhost";
$username = "root";
$DB = "test";

$conn = mysqli_connect($server, $username, "", $DB);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
} else {
?>
    <script>
        alert("Database Connected successfully");
    </script>
<?php
}
?>

SIGNUP PAGE

<?php
include 'CTNavbar.php';
?>

<?php

include 'DatabaseConnection.php';

if (isset($_POST['submit'])) {

    $name = $_POST['name'];
    $user = $_POST['user'];
    $email = $_POST['email'];
    $password = $_POST['password'];
$insertQ = "insert into
crazytaxies(name, user, email, password) values('$name', '$user',
'$email', '$password')";

    $res = mysqli_query($conn, $insertQ);

    if ($res) {
?>
        <script>
            alert("You are successfully registered");
        </script>
<?php
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

}
mysqli_close($conn);
?>

<div class="main-wrapper">
    <div class="form-container">
        <form action="" method="POST">
            <h3 class="text-uppercase">Signup</h3>
            <!-- Name input -->
            <div class="form-outline my-1">
                <input type="text" name="name" class="form-control" />
                <label class="form-label"
for="registerName">Name</label>
            </div>

            <!-- Username input -->


            <div class="form-outline my-1">
                <input type="text" name="user" class="form-control" />
      <label class="form-label"
for="registerUsername">Username</label>
            </div>

            <!-- Email input -->


            <div class="form-outline my-1">
                <input type="email" name="email" class="form-control"
/>
                <label
class="form-label" for="registerEmail">Email</label>
            </div>

            <!-- Password input -->


            <div class="form-outline my-1">
                <input type="password" name="password" class="form-
control" />
<label class="form-label" for="registerPassword">Password</label>
            </div>

            <!-- Repeat Password input -->


            <div class="form-outline my-1">
                <input type="password" id="rep-pass" class="form-
control" />

<label class="form-label"
for="registerRepeatPassword">Repeat password</label>
            </div>
               
            <!-- Checkbox -->
            <div class="form-check d-flex justify-content-center mb-
4">
                <input class="form-check-input me-2" type="checkbox"
value="" id="registerCheck" />
                <label class="form-check-label" for="registerCheck">
                    I have read and agree to the terms
                </label>
            </div>

            <!-- Submit button -->


            <input type="submit" name="submit" id="submit" class="btn
btn-primary my-1" style="width: 100%;">
        </form>
    </div>
</div>

5. Result/Output/Writing Summary:

Registration Form
Database
Learning outcomes (What I have learnt):

1. Learned about forms.


2. Learn to create Registration Form.
3. Learned to creating connection with database using PHP.
4. Learned to Send data to database table.

You might also like