1 回答

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();
}
?>
- 1 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)