-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess_AddAccounNo.php
35 lines (28 loc) · 1.13 KB
/
Process_AddAccounNo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
include 'DBconnect.php';
if(isset($_POST['accountNo'])){
$accountNo = $_POST['accountNo'];
$ctr = 0;
// Split the accounts account_nos by comma
$accountNos = explode(',', $accountNo);
foreach ($accountNos as $accountNo) {
$accountNo = trim($accountNo); // Trim whitespace from each accounts account_no
// Check if accounts account_no already exists
$checkQuery = "SELECT * FROM accounts WHERE account_no='$accountNo'";
$checkResult = mysqli_query($connect, $checkQuery);
if(mysqli_num_rows($checkResult) > 0){
echo "<div class='alert alert-danger my-2'>Account '$accountNo' already exists!</div>";
$ctr = 1;
} else {
// Insert new accounts into database
$insertQuery = "INSERT INTO accounts (account_no) VALUES ('$accountNo')";
if(!mysqli_query($connect, $insertQuery)){
$ctr = 1;
echo "<div class='alert alert-danger my-2'>Error adding accounts '$accountNo'!</div>";
}
}
}
if($ctr == 0) echo 'success';
mysqli_close($connect);
}
?>