Page 362 - CITS - CSA - TP (Volume 1) - Hindi
P. 362

कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS



                    <body>
                             <h2>Insert Data into MySQL Database</h2>

                             <form method=”post” action=”insert.php”>
                                             <label for=”username”>Username:</label><br>
                                             <input type=”text” id=”username” name=”username” required><br><br>
                                             <label for=”email”>Email:</label><br>
                                             <input type=”email” id=”email” name=”email” required><br><br>
                                             <input type=”submit” value=”Submit”>

                                     </form>
                          </body>
                 </html>
              3   ो ाम को C:\Apache24\htdocs म  index.html नाम के  फ़ो र म  सेव कर

           ii  डेटाबेस से कने  करने और इंसश न  ि या को संभालने के  िलए एक PHP     (insert.php) बनाएँ । (Create a PHP script
              (insert.php) to connect to the database and handle the insertion process.)
              1  टे  एिडटर ओपन करे

              2  िन िल खत कोड िलख

                          <html >
                 <head>
                      <title> </title>
                 </head>

                 <body>
                    <?php
                 // Database connection parameters
                 $servername = “localhost”;  // Change this if the MySQL server is on a different host
                 $username = “your_username”; // Change this to  MySQL username

                 $password = “your_password”; // Change this to  MySQL password
                 $database = “example_db”;    // Change this to  database name
                 // Create connection
                 $conn = new mysqli($servername, $username, $password, $database);
                 // Check connection
                 if ($conn->connect_error)

                 {
                      die(“Connection failed: “ . $conn->connect_error);
                 }
                 // Check if the form is submitted
                 if ($_SERVER[“REQUEST_METHOD”] == “POST”)

                 {
                              // Get form data
                              username = $_POST[“username”];



                                                           346

                                     CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 61
   357   358   359   360   361   362   363   364   365   366   367