Skip to content

Commit

Permalink
Added userupdate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabeel70 committed Jan 5, 2024
1 parent 62493d6 commit f1adef8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions includes/userupdate.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

if($_SERVER["REQUEST_METHOD"] == "POST"){

$username = $_POST["username"];
$password = $_POST["pwd"];
$email = $_POST["email"];

try {
require_once "dbh.inc.php";

//prepare parameters
// $query = "INSERT INTO users (username, pwd, email)
// VALUES(?, ?, ?);";

// $stmt = $pdo ->prepare($query);

// $stmt->execute([$username,$password, $email]);

//Named parameters
$query = "INSERT INTO users (username, pwd, email)
VALUES(:username, :pwd, :email);";

$stmt = $pdo ->prepare($query);

$stmt->bindParam(":username", $username);
$stmt->bindParam(":pwd", $password);
$stmt->bindParam(":email", $email);

$stmt->execute();

//Close the PDO connection
$pdo = null;
$stmt = null;
header("Location:../../../learn-php/basics/database.php");

exit();
} catch (PDOException $e) {
die("Query failed: " . $e->getMessage());
}

} else{
header("Location:../../../learn-php/basics/database.php");
}

0 comments on commit f1adef8

Please sign in to comment.