Skip to content

Commit

Permalink
Correct the link of form and created userdelete file in include direc…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
Nabeel70 committed Jan 5, 2024
1 parent ca6c36b commit 62493d6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion basics/dbform.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<h3 class="signup">Change Account</h3>
<form action="../includes/userdelete.inc.php" method="post">
<form action="../includes/userupdate.inc.php" method="post">
<input type="text" name="usernme" placeholder="Username">
<input type="password" name="pwd" placeholder="Password">
<input type="text" name="email" placeholder="Email">
Expand Down
44 changes: 44 additions & 0 deletions includes/userdelete.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 62493d6

Please sign in to comment.