0

我正在尝试通过表单向数据库中插入一些值,但为此必须连接表,并且我所做的方式对我不起作用......因为它涉及到安全问题代码,将在之后处理,但现在我将非常感谢一些帮助......数据没有存储在数据库中,在表单中输入值并单击保存按钮后,表单只是清空自己

<?php
session_start();
include('php/connectdb.php');

if(isset($_POST['firstname']) && isset($_POST['middlename']) && isset($_POST['lastname']) && isset($_POST['address']) && isset($_POST['home_num']) && isset($_POST['cell_num']) && isset($_POST['email']) && isset($_POST['trn']) && isset($_POST['hiredate']) && isset($_POST['status']) && isset($_POST['location']) && isset($_POST['shift']) && isset($_POST['rank']) && isset($_POST['dob']) && isset($_POST['maritalstatus']) && isset($_POST['gender']) && isset($_POST['height']) && isset($_POST['weight']) && isset($_POST['helmet_size']) && isset($_POST['coat_size']) && isset( $_POST['pant_size']) && isset($_POST['boot_size']) && isset($_POST['glove_size']))
{
    $firstname = ucfirst($_POST['firstname']);
    $middlename = ucfirst($_POST['middlename']);
    $lastname = ucfirst($_POST['lastname']);
    $address = $_POST['address'];
    $home_num = $_POST['home_num'];
    $cell_num = $_POST['cell_num'];
    $email = $_POST['email'];
    $trn = $_POST['trn'];
    $hiredate = $_POST['hiredate'];
    $status = $_POST['status'];
    $location = $_POST['location'];
    $shift = $_POST['shift'];
    $rank = $_POST['rank'];
    $dob = $_POST['dob'];
    $maritalstatus = $_POST['maritalstatus'];
    $gender = $_POST['gender'];
    $height = $_POST['height'];
    $weight = $_POST['weight'];
    $kinname = ucfirst($_POST['kinname']);
    $kinnumber = $_POST['kinnumber'];
    $helmet_size = $_POST['helmet_size'];
    $coat_size = $_POST['coat_size'];
    $pant_size = $_POST['pant_size'];
    $boot_size = $_POST['boot_size'];
    $glove_size = $_POST['glove_size'];
    $transfer = $_POST['transfer'];

    $transferTo = $_POST['transferTo'];
    $dateTransferredTo = $_POST['dateTransferredTo'];
    $transferFrom = $_POST['transferFrom'];
    $dateTransferredFrom = $_POST['dateTransferredFrom'];
    $rankTransferredWith = $_POST['rankTransferredWith'];


    $username = $_POST['username'];
    $password = $_POST['password'];

    if(!empty($firstname) && !empty($middlename) && !empty($lastname) && !empty($address) && !empty($home_num) && !empty($cell_num) && !empty($email) && !empty($trn) && !empty($hiredate) && !empty($status) && !empty($location) && !empty($shift) && !empty($rank) && !empty($dob) && !empty($maritalstatus) && !empty($gender) && !empty($height) && !empty($weight) && !empty($helmet_size) && !empty($coat_size) && !empty($boot_size) && !empty($glove_size) && !empty($transfer))
    {
        if($transfer == 'Yes'){
            $transfer = 1;
    }
    else{
        $transfer = 0;
    }

    $query1 = "INSERT INTO firefighterinfo(`firefighterinfo`.`firstName`, `firefighterinfo`.`middleName`, `firefighterinfo`.`lastName`, `firefighterinfo`.`address`, `firefighterinfo`.`telephone1`, `firefighterinfo`.`telephone2`, `firefighterinfo`.`emailAddress`, `firefighterinfo`.`taxRegistrationNo`, `firefighterinfo`.`hireDate`, `firefighterinfo`.`status`, `stationlocation`.`exactlocation`, `firefighterinfo`.`workShift`, `rank`.`rank`, `firefighterinfo`.`dateOfBirth`, `firefighterinfo`.`maritalStatus`, `firefighterinfo`.`gender`, `firefighterinfo`.`height`, `firefighterinfo`.`weight`, `firefighterinfo`.`kinName`, `firefighterinfo`.`kinContactNo`, `firefighterinfo`.`helmetSize`, `firefighterinfo`.`coatSize`, `firefighterinfo`.`pantSize`, `firefighterinfo`.`bootSize`, `firefighterinfo`.`gloveSize`, `firefighterinfo`.`transfer`)                     VALUES('$firstname', '$middlename', '$lastname', '$address', '$home_num', '$cell_num', '$email', '$trn', '$hiredate', '$status', '$location', '$shift', '$rank', '$dob', '$maritalstatus', '$gender', '$height', '$weight', '$kinname', '$kinnumber', '$helmet_size', '$coat_size', '$pant_size', '$boot_size', '$glove_size', '$transfer')
                SELECT `firefighterinfo`.fighterID`, `stationlocation`.`exactlocation`, `rank`.`rank` 
                FROM `firefighterinfo`
                INNER JOIN `stationlocation` ON `firefighterinfo`.`StationLocation_locationID` = `stationlocation`.locationID
                INNER JOIN `rank` ON `firefighterinfo`.`Rank_rankID` = `rank`.`rankID`";

    $query2 = "INSERT INTO transfer(`transferToStation`,`transferToDate`,`transferFromStation`,`transferFromDate`,`rankTranferredWith`) VALUES('$transferTo', '$dateTransferredTo', '$transferFrom', '$dateTransferredFrom', '$rankTransferredWith')";

    $query3 = "INSERT INTO user(`username`, `password`) VALUES ('$username','$password')";

    if($_POST['kinname'] == '' || $_POST['kinnumber']== ''){
        $_POST['kinname'] = null;
        $_POST['kinnumber'] = null;
    }

    $result = false;
    if(mysql_query('BEGIN')){
        if(mysql_query($query1) && mysql_query($query2) && mysql_query($query3))
        {
            $result = mysql_query('COMMIT');
            echo '<script type="text/javascript">
                alert("Insert Successful!");
              </script>';
        }
        else
        {
            mysql_query('ROLLBACK');
            echo '<script type="text/javascript">
                alert("Insert Unsuccessful!");
              </script>';
        }
    }
}

}
?>
4

0 回答 0