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

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

插入具有多個(gè)動(dòng)態(tài)輸入元素的函數(shù)

插入具有多個(gè)動(dòng)態(tài)輸入元素的函數(shù)

PHP
尚方寶劍之說 2021-11-05 10:49:13
我目前正在嘗試在我的數(shù)據(jù)庫(kù)中的兩個(gè)不同表之間創(chuàng)建一些動(dòng)態(tài)內(nèi)容。首先,“table1”將包含這些值。該表可以動(dòng)態(tài)擴(kuò)展。這些條目創(chuàng)建動(dòng)態(tài)表單就像創(chuàng)建動(dòng)態(tài)輸入標(biāo)簽一樣,就像在 table1 中找到的一樣。我特別想做的是,每當(dāng)我提交表單時(shí),我也想在 table2 中傳遞這些動(dòng)態(tài)條目。這是該項(xiàng)目的完整示例。甚至創(chuàng)建表格和示例條目?;旧衔也恢烙檬裁磥泶妗埃???” 在“insert_into_table2”函數(shù)中。從現(xiàn)在開始非常感謝。<?phpcheck_tables();insert_tables();if(isset($_GET['new']) && isset($_GET['new']) == ''){    $somevalue = 'Some Value';    insert_into_table2($somevalue);}function check_tables(){    $connection = mysqli_connect("localhost", "testuser", "testpass", "test");    $sql = "CREATE TABLE IF NOT EXISTS `table1` (            `table1_ID` int(11) NOT NULL AUTO_INCREMENT,            `table1_no` int(3) NOT NULL,            `table1_title` varchar(255) NOT NULL,            `table1_description` varchar(255) NOT NULL,            PRIMARY KEY (`table1_ID`)        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";    if ($connection->query($sql) === TRUE) {}    $connection->close();    $connection = mysqli_connect("localhost", "testuser", "testpass", "test");    $sql = "CREATE TABLE IF NOT EXISTS `table2` (            `table2_ID` int(11) NOT NULL AUTO_INCREMENT,            `table2_row1` varchar(255) NOT NULL,             `name` varchar(255) DEFAULT NULL,            `lastname` varchar(255) DEFAULT NULL,             PRIMARY KEY (`table2_ID`)        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";    if ($connection->query($sql) === TRUE) {}    $connection->close();}function insert_tables(){    $connection = mysqli_connect("localhost", "testuser", "testpass", "test");    $sql = "SELECT * FROM table1";    $result = $connection->query($sql);    if (mysqli_num_rows($result) < 1) {        $sql = "INSERT INTO `table1` (`table1_ID`, `table1_no`, `table1_title`, `table1_description`) VALUES                (1, 1, 'Name', 'name'),                (2, 2, 'Lastname', 'lastname');";        if ($connection->query($sql) === TRUE) {}        $connection->close();    }}
查看完整描述

1 回答

?
慕的地10843

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

幾天后,沒有其他人的幫助。我想通了,只是想在這里分享,如果其他人有興趣。


首先,我為提交按鈕分配了一個(gè)名稱以使觸發(fā)器工作。而不是這個(gè);


<input type="submit"/>

我用過這個(gè);


<input type="submit" name="new_entry"/>

當(dāng)然,還要更改觸發(fā)器。從;


isset($_GET['new']) && isset($_GET['new']) == ''

到;


isset($_POST['new_entry'])

最后,我能夠從列和輸入中獲取值并在下面添加代碼;


function insert_into_table2($somevalue){

    $connection = mysqli_connect("localhost", "testuser", "testpass", "test");

代碼是;


$sqlfc = "SELECT * FROM table1 ORDER BY table1_no ASC";

    $result = $connection->query($sqlfc);

    $columns_ = array();

    if (mysqli_num_rows($result) > 0) {

        $values = implode("', '", $_POST["name"]);

        while($row = mysqli_fetch_array($result)){

            $columns_[] = $row['table1_description'];

        }

        $columns = implode(", ",$columns_);

    }

對(duì)于決賽,我能夠更改問題標(biāo)記區(qū)域。比如從;


$sql = "INSERT INTO `table2` (`table2_row1`, '???') VALUES ('$somevalue', '???');";

到;


$sql = "INSERT INTO table2 (table2_row1, $columns) VALUES ('$somevalue', '$values');";

現(xiàn)在一切正常。我以為我可以從這里得到幫助,但這次我沒有那么幸運(yùn)。希望這至少可以幫助其他人。


查看完整回答
反對(duì) 回復(fù) 2021-11-05
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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