Untitled

 avatar
unknown
plain_text
a year ago
2.7 kB
6
Indexable
<?php

include '../db/connection.php';

$txtemail = $txtFName = $txtLName = $txtgender = $txtbirth = $txtcontact = $txtaddress = $txtnationality = $txtpass = '';
if (isset($_POST['btnsubmit'])){

    $txtemail = $_POST['txtemail'];
    $txtFName = $_POST['txtFName'];
    $txtLName = $_POST['txtLName'];
    $txtgender = $_POST['txtgender'];
    $txtbirth = $_POST['txtbirth'];
    $txtcontact = $_POST['txtcontact'];
    $txtaddress = $_POST['txtaddress'];
    $txtnationality = $_POST['txtnationality'];
    $txtpass = password_hash($_POST['txtpass'] , PASSWORD_BCRYPT);

    $strsql = "INSERT INTO dbo.Tbl_Customer (Email, Fname, Lname, gndr, Bdate, ConNum, Addr, Natly, Pass) VALUES (?,?,?,?,?,?,?,?,?)";
    $params = array($txtemail, $txtFName, $txtLName, $txtgender, $txtbirth, $txtcontact, $txtaddress, $txtnationality, $txtpass);
    $query = sqlsrv_query($conn, $strsql, $params);

    if ($query) {
        $getEmailIdQuery = "SELECT AcctID FROM Tbl_Customer WHERE email = ?";
        $getEmailIdParams = array($txtemail);
        $getEmailIdResult = sqlsrv_query($conn, $getEmailIdQuery, $getEmailIdParams);

        if ($getEmailIdResult) {
            $row = sqlsrv_fetch_array($getEmailIdResult, SQLSRV_FETCH_ASSOC);
            $customerIdByEmail = $row['AcctID'];

            $balanceValue = 100; 
            $strsqlBalance = "INSERT INTO Tbl_Balance (AcctID, Balance) VALUES ('$customerIdByEmail', '$balanceValue')";
             $queryBalance = sqlsrv_query($conn, $strsqlBalance);

            sqlsrv_free_stmt($getEmailIdResult);

            if (!$queryBalance) {
                   die(print_r(sqlsrv_errors(), true));
                     echo '<script type="text/javascript">';
                     echo 'alert("Incorrect Input");';
                     echo 'window.location.href = "addCustomer.php";';
                     echo '</script>';
            } 
            else {




            }
        } else {
            echo "Error fetching Customer ID: " . print_r(sqlsrv_errors(), true);
        }

    }

    if (!$query) {
        die(print_r(sqlsrv_errors(), true));
        echo '<script type="text/javascript">';
        echo 'alert("Incorrect Input");';
        echo 'window.location.href = "addCustomer.php";';
        echo '</script>';
    }
    
    

        else {
            sqlsrv_close($conn);
           
            echo '<script type="text/javascript">';
            echo 'alert("Added Succesfully");';
            echo 'window.location.href = "customers.php";';
            echo '</script>';
            
            exit();
        }
    }


?>

Editor is loading...
Leave a Comment