s44
This commit is contained in:
@@ -6,28 +6,41 @@
|
||||
<h4>Customer Registration</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
require('../.hta_config/conf.php');
|
||||
<?php
|
||||
require('../.hta_config/conf.php');
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
try {
|
||||
$customerId = str_replace('.', '', uniqid('cust_', true));
|
||||
$userPassword = md5($_POST['password']);
|
||||
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
try {
|
||||
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$stmt = $db->prepare("INSERT INTO customers (name, mobile, email) VALUES (:name, :mobile, :email)");
|
||||
$stmt->bindParam(':name', $_POST['name']);
|
||||
$stmt->bindParam(':mobile', $_POST['mobile']);
|
||||
$stmt->bindParam(':email', $_POST['email']);
|
||||
$stmt = $db->prepare("INSERT INTO customers (name, mobile, email, customerId) VALUES (:name, :mobile, :email, :customerId)");
|
||||
$stmt->bindParam(':name', $_POST['name']);
|
||||
$stmt->bindParam(':mobile', $_POST['mobile']);
|
||||
$stmt->bindParam(':email', $_POST['email']);
|
||||
$stmt->bindParam(':customerId', $customerId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo '<div class="alert alert-success">New Customer <strong>' . htmlspecialchars($_POST['name']) . '</strong> created successfully.</div>';
|
||||
} else {
|
||||
echo '<div class="alert alert-danger">Error executing statement: ' . $stmt->errorInfo()[2] . '</div>';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
$stmt2 = $db->prepare("INSERT INTO users (name, mobile, email, type, password, customerId) VALUES (:name, :mobile, :email, :type, :password, :customerId)");
|
||||
$stmt2->bindParam(':name', $_POST['name']);
|
||||
$stmt2->bindParam(':mobile', $_POST['mobile']);
|
||||
$stmt2->bindParam(':email', $_POST['email']);
|
||||
$stmt2->bindParam(':type', $_POST['type']);
|
||||
$stmt2->bindParam(':password', $userPassword);
|
||||
$stmt2->bindParam(':customerId', $customerId);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$stmt2->execute();
|
||||
echo '<div class="alert alert-success">New Customer <strong>' . htmlspecialchars($_POST['name']) . '</strong> created successfully.</div>';
|
||||
} else {
|
||||
echo '<div class="alert alert-danger">Error inserting into customers table: ' . $stmt->errorInfo()[2] . '</div>';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="POST">
|
||||
<div class="form-group">
|
||||
<label for="name">Name:</label>
|
||||
@@ -42,6 +55,20 @@
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="type">User Type:</label>
|
||||
<select class="form-control" name="type" id="type" require>
|
||||
<option value="">-Select-</option>
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" class="form-control" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success btn-block mt-2">Save Customer</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
<?php
|
||||
session_start();
|
||||
require('../.hta_slug/_header.php');
|
||||
require('../.hta_slug/_nav.php');
|
||||
require_once('../.hta_config/var.php');
|
||||
if(isset($_SESSION['isLogedin']) && $_SESSION['isLogedin'] === true && isset($_SESSION['userType']) && $_SESSION['userType'] === 'admin'){
|
||||
require_once('../.hta_config/var.php');
|
||||
|
||||
$url = explode('/', $_SERVER['REQUEST_URI']);
|
||||
if (strpos($url[1], "?") !== false) {
|
||||
$url2 = explode('?', $url[1]);
|
||||
$slug=$url2[0];
|
||||
} else $slug=$url[2];
|
||||
|
||||
require_once('../.hta_slug/_header.php');
|
||||
|
||||
if($slug=="") require_once('.hta_slug/_home.php');
|
||||
elseif(file_exists(".hta_slug/".$slug.".php")) include ".hta_slug/".$slug.".php";
|
||||
else require_once('.hta_slug/_404.php');
|
||||
} else{
|
||||
header("location:/");
|
||||
}
|
||||
|
||||
|
||||
$url = explode('/', $_SERVER['REQUEST_URI']);
|
||||
if (strpos($url[1], "?") !== false) {
|
||||
$url2 = explode('?', $url[1]);
|
||||
$slug=$url2[0];
|
||||
} else $slug=$url[2];
|
||||
|
||||
require_once('../.hta_slug/_header.php');
|
||||
|
||||
if($slug=="") require_once('.hta_slug/_home.php');
|
||||
elseif(file_exists(".hta_slug/".$slug.".php")) include ".hta_slug/".$slug.".php";
|
||||
else require_once('.hta_slug/_404.php');
|
||||
|
||||
require_once('../.hta_slug/_footer.php');
|
||||
Reference in New Issue
Block a user