第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

為什么 SQL-Server 會(huì)為單個(gè)條目保存重復(fù)數(shù)據(jù)?

為什么 SQL-Server 會(huì)為單個(gè)條目保存重復(fù)數(shù)據(jù)?

PHP
慕容3067478 2022-01-08 20:25:45
我在 php 中開發(fā)了一個(gè)基于 CRUD 的 Web 應(yīng)用程序。這是一個(gè)表單,其輸入數(shù)據(jù)保存在 sql server 數(shù)據(jù)庫中。即使用戶填寫一次,數(shù)據(jù)庫也會(huì)為其保存多個(gè)條目。問題出在數(shù)據(jù)庫中,似乎表單已成功提交。任何人都可以幫忙嗎?謝謝這是代碼:<?phpob_start();require_once 'db-connect.php';require_once 'email.php';        if(isset($_POST['pEmail'])){    $fName = filter_input(INPUT_POST, "fName") ? filter_input(INPUT_POST, 'fName') : null;    $lName = filter_input(INPUT_POST, "lName")? filter_input(INPUT_POST, 'lName') : null;    $mName = filter_input(INPUT_POST, "mName")? filter_input(INPUT_POST, 'mName') : null;    $tempRace = filter_input(INPUT_POST, "race", FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);    $race = (is_array($tempRace)) ? implode(',', $tempRace) : null;    $hEthnicity = filter_input(INPUT_POST, "hEthnicity") ? filter_input(INPUT_POST, 'hEthnicity') : null;    $gender = filter_input(INPUT_POST, "gender") ? filter_input(INPUT_POST, 'gender') : null;    $age = filter_input(INPUT_POST, "age") ? filter_input(INPUT_POST, 'age') : null;    $education = filter_input(INPUT_POST, "education") ? filter_input(INPUT_POST, 'education') : null;    $conn = DB::databaseConnection();    $conn->beginTransaction();    $sql = "INSERT INTO dbo.premedical ( FName,LName, MidInitial, Race, Ethnicity, Gender, Age, SchoolYear, Gpa, HPhone, CPhone, PEmail, AEmail, MailAddress, MailCity) VALUES             ( :fName,:lName, :mName, :race, :hEthnicity, :gender,:age, :education, :gpa, :hPhone, :cPhone, :pEmail, :aEmail, :inputAddress, :inputCity)";    $q = $conn->prepare($sql);    $q->execute(array($fName,  $lName, $mName, $race, $hEthnicity, $gender, $age,   $education, $gpa, $hPhone, $cPhone, $pEmail, $aEmail, $inputAddress, $inputCity));
查看完整描述

1 回答

?
萬千封印

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊

調(diào)用$q->execute會(huì)觸發(fā)執(zhí)行過程,即使您在邏輯檢查中使用它 - 所以它會(huì)執(zhí)行兩次。您應(yīng)該將其更新為:


<?php

ob_start();

require_once 'db-connect.php';

require_once 'email.php';        


if(isset($_POST['pEmail'])){

    $fName = filter_input(INPUT_POST, "fName") ? filter_input(INPUT_POST, 'fName') : null;

    $lName = filter_input(INPUT_POST, "lName")? filter_input(INPUT_POST, 'lName') : null;

    $mName = filter_input(INPUT_POST, "mName")? filter_input(INPUT_POST, 'mName') : null;

    $tempRace = filter_input(INPUT_POST, "race", FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);

    $race = (is_array($tempRace)) ? implode(',', $tempRace) : null;

    $hEthnicity = filter_input(INPUT_POST, "hEthnicity") ? filter_input(INPUT_POST, 'hEthnicity') : null;

    $gender = filter_input(INPUT_POST, "gender") ? filter_input(INPUT_POST, 'gender') : null;

    $age = filter_input(INPUT_POST, "age") ? filter_input(INPUT_POST, 'age') : null;

    $education = filter_input(INPUT_POST, "education") ? filter_input(INPUT_POST, 'education') : null;

    $gpa = filter_input(INPUT_POST, "gpa") ? filter_input(INPUT_POST, 'gpa') : null;

    $hPhone = filter_input(INPUT_POST, "hPhone") ? filter_input(INPUT_POST, 'hPhone') : null;

    $cPhone = filter_input(INPUT_POST, "cPhone") ? filter_input(INPUT_POST, 'cPhone') : null;

    $pEmail = filter_input(INPUT_POST, "pEmail") ? filter_input(INPUT_POST, 'pEmail') : null;

    $aEmail = filter_input(INPUT_POST, "aEmail") ? filter_input(INPUT_POST, 'aEmail') : null;

    $inputAddress = filter_input(INPUT_POST, "inputAddress") ? filter_input(INPUT_POST, 'inputAddress') : null;

    $inputCity = filter_input(INPUT_POST, "inputCity") ? filter_input(INPUT_POST, 'inputCity') : null;


    $conn = DB::databaseConnection();

    $conn->beginTransaction();

    $sql = "INSERT INTO dbo.premedical ( FName,LName, MidInitial, Race, Ethnicity, Gender, Age, SchoolYear, Gpa, HPhone, CPhone, PEmail, AEmail, MailAddress, MailCity) VALUES 

            ( :fName,:lName, :mName, :race, :hEthnicity, :gender,:age, :education, :gpa, :hPhone, :cPhone, :pEmail, :aEmail, :inputAddress, :inputCity)";


    $q = $conn->prepare($sql);

    $result = $q->execute(array($fName,  $lName, $mName, $race, $hEthnicity, $gender, $age,   $education, $gpa, $hPhone, $cPhone, $pEmail, $aEmail, $inputAddress, $inputCity));


    if ($result) {

        $conn->commit(); 


        if (Form::mailer($fName,  $lName, $mName, $race, $hEthnicity, $gender, $age,   $education, $gpa, $hPhone, $cPhone, $pEmail, $aEmail, $inputAddress, $inputCity)) {

            echo '

            <script >

                alert("Thank you for registration.");

            </script>';

        }


        return true; 

    } else {

        echo '

        <script>

            alert("Error, please try submitting again. Error code 1");

            window.history.back();

        </script>';

    }

}

?>


查看完整回答
反對(duì) 回復(fù) 2022-01-08
  • 1 回答
  • 0 關(guān)注
  • 151 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)