SQL Programs

SQL Programs

Table of Contents

Insert values in Table

				
					<?php
$servername = "localhost";
$username = "vinay";
$password = "123456";
$dbname = "vinay";

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

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

// select database
$username=$_POST["username"];
$password=$_POST["password"];
$email=$_POST["email"];
$mobile=$_POST["mobile"];
$address=$_POST["address"];
$dateofbirth=$_POST["dateofbirth"];


$sql = "INSERT INTO regform (username, password, email, mobile, address, dateofbirth)
VALUES ('$username', '$password', '$email', '$mobile', '$address', '$dateofbirth')"
;
$result = $conn->query($sql);


?>
				
			

Select Gender = Female

				
					<?php
$servername = "localhost";
$username = "rahul";
$password = "123456";
$dbname = "smartweb";

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

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

// select database
$gender=$_POST["gender"];

$sql = "SELECT * FROM registrationform where gender='$gender'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<h2>".$row["username"]. "</h2>".
        $row["email"]. "<br>".
        $row["mobile"]. "<br>---------------------------<br>";
    }
} else {
    echo "0 results";
}
?>
				
			

Take Your Free Live Demo Class Now

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Send You the Course Fees Details In Below Number

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

Enter Your DETAILS BELOW TO take

free demo class