gpt4 book ai didi

php - 了解 $_REQUEST。为什么这没有得到 $_REQUEST ['submit' ]?

转载 作者:行者123 更新时间:2023-11-29 00:32:05 24 4
gpt4 key购买 nike

下面的代码可以从数据库中删除行,但不能插入。这是为什么?

<?php

mysql_connect("localhost","formuser","password") or die(mysql_error());
mysql_select_db("formpractice") or die(mysql_error());


$name = $_POST['name'];
$address = $_POST['address'];

// Add into DB Query
$insert = "INSERT INTO Users(name, address) VALUES ('$name', '$address')";
$insert_result = mysql_query($insert);

// Delete from DB Query
$delete = "DELETE FROM Users WHERE name = '$name' OR address = '$address'";
$delete_result = mysql_query($delete);

if(isset($_REQUEST['submit'])) {
if ($insert_result) {
echo "Success";
} else {
echo "Failed to submit";
}
echo 'Submit Request';

} else if (isset($_REQUEST['delete'])) {
if ($delete_result) {
echo "Deleted";
} else {
echo "Failed to submit";
}
}


?>

最佳答案

试试这个:

mysql_connect("localhost","formuser","password") or die(mysql_error());
mysql_select_db("formpractice") or die(mysql_error());

$name = $_POST['name'];
$address = $_POST['address'];

if(isset($_REQUEST['submit'])) {
// Add into DB Query
$insert = "INSERT INTO Users(name, address) VALUES ('$name', '$address')";
$insert_result = mysql_query($insert);
if ($insert_result) {
echo "Success";
} else {
echo "Failed to submit";
}
echo 'Submit Request';

} else if (isset($_REQUEST['delete'])) {
// Delete from DB Query
$delete = "DELETE FROM Users WHERE name = '$name' OR address = '$address'";
$delete_result = mysql_query($delete);
if ($delete_result) {
echo "Deleted";
} else {
echo "Failed to submit";
}
}

关于php - 了解 $_REQUEST。为什么这没有得到 $_REQUEST ['submit' ]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com