How to give two perameters in GET request in php?

How to give two parameters in GET request in php

In GET method the data is sent as URL parameters that are usually strings of name and value pairs separated by ampersands (&). In general, a URL with GET data will look like this:

http://www.example.com/action.php?name=Sam&weight=55

The bold parts in the URL are the GET parameters and the italic parts are the value of those parameters. More than one parameter=value can be embedded in the URL by concatenating with ampersands (&). One can only send simple text data via GET method.


Important Note : 
In this above video and below source code i am give only simple explanation of GET request you must not give this type of GET request in your project
Source Code :
1. DATABASE TABLE STRUCTURE:
Database Name : student_information
table Name : mba_student
table column name : 
    1.srno [auto increment];
    2.fname[varchar][length 15]
    3.lname[varchar][length 15]
    4.email[varchar][length 50]
    5.cno[varchar][length 12]
    6.time[datatime]
2. DATABASE CONNECTION :
<?php
    $servername = "localhost";
    $username = "root";
    $pwd = "";
    $dbname = "student_information";
    $con = mysqli_connect($servername, $username, $pwd, $dbname);
    if ($con) {
        // echo 'Connection Succeessfully';
    } else {
        echo 'Check your Connection ';
    }
?>
3. Insertion Query and Student Information Form:
<?php
    include('dbconnect.php');
    if ($_SERVER['REQUEST_METHOD'] == "POST") {
        $fname = $_POST['fname'];
        $lname = $_POST['lname'];
        $email = $_POST['email'];
        $cno = $_POST['cno'];
        $insert_query = "INSERT INTO `mba_student` ( `fname`, `lname`, `email`, `cno`) VALUES ( '$fname', '$lname', '$email', '$cno');";
        $result = mysqli_query($con, $insert_query);
        if ($result) {
            header("location:home_page.php?insert='true'&student_name='.$fname.'&student_surname='.$lname.'");
        }
    }
    ?>
    <!doctype html>
    <html lang="en">
    
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    
        <!-- Bootstrap CSS -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
    
        <title>How to give more than one paramenter in GET request in php</title>
    </head>
    
    <body>
        <div class="container my-5">
            <h2>Student Information Form</h2>
            <form method="POST" name="studentForm" id="studentForm">
                <div> class="mb-3">
                    <label> for="fname" class="form-label">First Name:</label>
                    <input type="text" autocomplete="off" class="form-control" id="fname" name="fname">
                </div>
                <div> class="mb-3">
                    <label> for="lname" class="form-label">Last Name:</label>
                    <input type="text" autocomplete="off" class="form-control" id="lname" name="lname">
                </div>
                <div> class="mb-3">
                    <label> for="email" class="form-label">Email address:</label>
                    <input type="email" autocomplete="off" class="form-control" id="email" aria-describedby="emailHelp"
                        name="email">
                    <div> id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
                </div>
                <div> class="mb-3">
                    <label> for="cno" class="form-label">Contact No:</label>
                    <input type="number" autocomplete="off" class="form-control" id="cno" name="cno">
                </div>
                <button> type="submit" class="btn btn-primary" id="sBtn">Submit</button>
            </form>
        </div>
    
        <script>> src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
        <script>> src="logic.js"></script>
    </body>
    
    </html>
4. Home Page:
   <!doctype html>
    <html lang="en">
    
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
        <title>Home Page</title>
    </head>
    
    <body>
        <h2>Home page</h2>
        <?php
        $insert = $_GET['insert'];
        if ($insert == true) {
            echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
      <strong>Success!</strong> Your Information Has Been Inserted.
      <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>';
        }
        $student_name = $_GET['student_name']; <!-- we are give get request here useing global variable $_GET -->
        echo "Student Name Is=" . $student_name;
        echo "<br>";
        $student_surname = $_GET['student_surname'];
        echo "Student Surname Is=" . $student_surname;
        ?>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js">
        </script>
    </body>
    
    </html>

Post a Comment

0 Comments