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

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




           ii  डेटाबेस से कने  करने और यूजर इनपुट के  आधार पर अपडेट  ोसेस को ह डल करने के  िलए एक PHP     (update.php) बनाएँ ।
              1  टे  एिडटर ओपन करे

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

                          <html >
                 <head> HTML form </title>
                 </head>
                 <body>

                            <?php
                   // Database connection parameters
                   $servername = “localhost”;  // Change this if  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
                       //$id = $_POST[“id”];
                       $newUsername = $_POST[“username”];
                       $newEmail = $_POST[“email”];

                      // Prepare and execute the SQL statement to update data in the table
                      $stmt = $conn->prepare(“UPDATE users SET email = ? WHERE username = ?”);
                      $stmt->bind_param(“ss”,$newEmail,$newUsername);
                         if ($stmt->execute())

                   {
                          echo “Record updated successfully”;
                      }
                   else

                   {
                               echo “Error: “ . $conn->error;
                      }



                                                           349

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