Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

Row Major Order And Column Major Order in Array-:


The Formula to calculate the address of an element in 2-d array using Row Major Order would be-:
Arr( A[i][j])=BA+[i*n+j]*w
where,
BA-:Base Address
w-:width [ data type of array]
i-:subscript of array element
j-:subscript of array element
n-:number of column
m-:number of rows
Q- Find address of element in array having location a[2][3] with base address 100 and it is an integer type array,and the size of array is a[3][4]?
=> we know that,
               Arr( A[i][j])=BA+[i*n+j]*w
      here,
               a[2][3]=100+[2*4+3]*2
               a[2][3]=100+[8+3]*2
               a[2][3]=100+22
               a[2][3]=122. 
The Formula to calculate the address of an element in 2-d array using Column Major Order would be-:
Arr( A[i][j])=BA+[j*n+i]*w
where,
BA-:Base Address
w-:width [ data type of array]
i-:subscript of array element
j-:subscript of array element
n-:number of column
m-:number of rows   
Q- Find address of element in array having location a[2][3] with base address 100 and it is an integer type array,and the size of array is a[3][4]?
=> we know that,
               Arr( A[i][j])=BA+[j*n+i]*w
      here,
               a[2][3]=100+[3*3+3]*2
               a[2][3]=100+[9+2]*2
               a[2][3]=100+22
               a[2][3]=122.   
Watch The Video Below

ads


<!DOCTYPE html>
<html>
<head>
    <title>User Registration</title>
</head>
<body>
    <h1>User Registration</h1>
    <form method="post" action="register.php">
        <label for="firstname">First Name:</label>
        <input type="text" name="firstname" required>
        <br>
        <label for="lastname">Last Name:</label>
        <input type="text" name="lastname" required>
        <br>
        <label for="email">Email:</label>
        <input type="email" name="email" required>
        <br>
        <label for="password">Password:</label>
        <input type="password" name="password" required>
        <br>
        <label for="confirm_password">Confirm Password:</label>
        <input type="password" name="confirm_password" required>
        <br>
        <label for="is_admin">Register as Admin:</label>
        <input type="checkbox" name="is_admin" value="1">
        <br>
        <button type="submit">Register</button>
    </form>
</body>
</html>




<?php
// Establish database connection (Replace the placeholders with your database credentials)
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Function to safely handle user inputs
function sanitize_input($input)
{
    return htmlspecialchars(trim($input));
}

// Handle registration form submission
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $firstname = sanitize_input($_POST["firstname"]);
    $lastname = sanitize_input($_POST["lastname"]);
    $email = sanitize_input($_POST["email"]);
    $password = $_POST["password"];
    $confirm_password = $_POST["confirm_password"];
    $is_admin = isset($_POST["is_admin"]) && $_POST["is_admin"] === "1" ? 1 : 0;

    // Additional validation can be performed here (e.g., password match check, email format validation, etc.)

    // Hash the password before storing it in the database
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);

    // Prepare and execute the SQL query to insert the new user into the database
    $sql = "INSERT INTO users (firstname, lastname, email, password, is_admin) 
            VALUES ('$firstname', '$lastname', '$email', '$hashed_password', $is_admin)";

    if ($conn->query($sql) === TRUE) {
        echo "Registration successful!";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}

$conn->close();
?>







Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey