gpt4 book ai didi

php - 在同一页面添加mysql和删除

转载 作者:行者123 更新时间:2023-11-29 19:18:14 24 4
gpt4 key购买 nike

这是我的脚本

require('dbcon2.php');


if(isset($_GET['submit1'])) {
if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {

mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");

}

} elseif(isset($_GET['submit2'])) {

if(isset($_POST['post_id_news2'])) {
$usun = $_POST['post_id_news2'];

mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."");
} else {
echo 'Proba usunieca postu o pustym id.';
}

}

我想在一页上执行此操作,在添加删除之前(呵呵)没关系,但我想做删除选项,但没有任何作用,零错误,我只是按输入,什么也没有发生。

HTML:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta charset="utf-8">

<style type="text/css">
.cztery {
background: pink;
height:705px;
width:40%;
float:right;
}
.czteryipol {
background: red;
height:705px;
width:40%;
float:right;
}
</style>
</head>
<body>
<div class="cztery">
<h1 align="center">
<a href="html/news_podg.php" target="_blink">
PODGLĄD
</a>
</h1>
<table border="5" bordercolor="#a64dff" align="center" style="max-width:20px;">
<?php
$result = mysqli_query($connect,"SELECT autor,id_news FROM news GROUP BY id_news");
while($row = mysqli_fetch_array($result))
{
echo '<tr><td>'.$row['id_news'].'</td><td>'.$row['autor'].'</td></tr>';
}
?>
</table>
</div>
<div class="czteryipol">
<h1 align="center">
EDYCJA
</h1>
<form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">

<h2>
Autor<br> <input type="text" size="20" name="post_autor"/>
</h2>


<h2>
Dodaj artykuł:
</h2>
<textarea name="post_tresc" align="center" form="usrform"></textarea><br>

<input name="submit1" type="submit" value="OK"/><br>
</form>

<form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">
<h1 align="center">
Usuń artykuł
</h1>
<h2>
Numer artykułu<br> <input type="text" size="5" name="post_id_news2"/>
</h2>
<input name="submit2" value="OK" type="submit"/><br>
</form>
</div>
</body>
</html>

如果有人能告诉我我的错误在哪里,我将非常感激

最终编辑:

感谢您的帮助,我解决了这个问题:

而不是这个

($_GET['submit1']) 

($_POST['submit1'])

最佳答案

大概......而不是if(isset($_GET['submit1']))使用if(isset($_POST['submit1']))

关于php - 在同一页面添加mysql和删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42590326/

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