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

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

在 PHP 問(wèn)題中插入數(shù)據(jù)庫(kù)中的按鈕和函數(shù)記錄

在 PHP 問(wèn)題中插入數(shù)據(jù)庫(kù)中的按鈕和函數(shù)記錄

PHP
HUWWW 2023-05-26 17:32:21
這是代碼,不起作用 -<form method="post">    <input type="submit" name="zapis" id="zapisk" value="Запис" /><br/></form><?phpfunction zapisk(){$servername = "localhost";    $username = "test";    $password = "";    $dbname = "myDB";// Create connection    $conn = new mysqli($servername, $username, $password, $dbname);// Check connection    if ($conn->connect_error) {        die("Connection failed: " . $conn->connect_error);    }    $sql = "INSERT INTO MyGuests (firstname, lastname, email)VALUES ('John', 'Doe', 'john@example.com')";    if ($conn->query($sql) === TRUE) {        echo "New record created successfully";    } else {        echo "Error: " . $sql . "<br>" . $conn->error;    }    $conn->close();}//{echo "Your test function on button click is working";}//if(array_key_exists('zapis',$_POST)){zapisk();}?>如果我激活最后兩行,此時(shí)作為評(píng)論,該功能將起作用。是否有可能,該功能可以在不使用最后兩行的情況下工作。
查看完整描述

1 回答

?
天涯盡頭無(wú)女友

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

zapisk提交表單時(shí)必須調(diào)用函數(shù)。


<form method="post">

    <input type="submit" name="zapis" id="zapisk" value="Запис" /><br/>

</form>


<?php


function zapisk(){

    $servername = "localhost";

    $username = "test";

    $password = "";

    $dbname = "myDB";


// Create connection

    $conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

    if ($conn->connect_error) {

        die("Connection failed: " . $conn->connect_error);

    }


    $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')";


    if ($conn->query($sql) === TRUE) {

        echo "New record created successfully";

    } else {

        echo "Error: " . $sql . "<br>" . $conn->error;

    }


    $conn->close();

}


// Check form submitted and post has zapis value. 

if(!empty($_POST['zapis'])){

   zapisk();

}


?>



或者您不使用函數(shù)并在 if 語(yǔ)句中編寫(xiě)代碼:


<form method="post">

    <input type="submit" name="zapis" id="zapisk" value="Запис" /><br/>

</form>


<?php


// Check form submitted and post has zapis value. 

if(!empty($_POST['zapis'])){

    $servername = "localhost";

    $username = "test";

    $password = "";

    $dbname = "myDB";


// Create connection

    $conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

    if ($conn->connect_error) {

        die("Connection failed: " . $conn->connect_error);

    }


    $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')";


    if ($conn->query($sql) === TRUE) {

        echo "New record created successfully";

    } else {

        echo "Error: " . $sql . "<br>" . $conn->error;

    }


    $conn->close();


}


?>


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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