gpt4 book ai didi

php - 刷新或打开页面会将空数据插入我的数据库! PHP, 来自

转载 作者:行者123 更新时间:2023-12-01 00:13:34 26 4
gpt4 key购买 nike

我有一个包含多个输入的表单。但是,当我只是简单地加载页面时,一个空白项目被添加到数据库中。即使我第一次进入该站点,清除了所有 cookie,它仍然会向数据库添加空数据这是为什么?

<body>





<hr></hr>
<div
style="

margin-left:auto;
margin-right:auto;

width:600px;
"
>
<form method="post" action="admin.php" name="main" id="main">
Post to:
<select name="wheretopost" onchange="testValue(this);" name="select" id="select">
<option value="blog">Blog</option>
<option name='links' value="links">Links</option>
<option value="apparel">Apparel</option>
<option value="goods">Goods</option>
</select>
<div class="productKind" style="padding:10px;">
Mens<input type="radio" name="productKind" id="productKind" value="Mens">
Womens<input type="radio" name="productKind" id="productKind" value="Womens">
Kids<input type="radio" name="productKind" id="productKind" value="Kids">
</div>
<div class="goodsKind" style="padding:10px;">
Stickers<input type="radio" name="goodsKind" id="goodsKind" value="Stickers">
Incense<input type="radio" name="goodsKind" id="goodsKind" value="Incense">
Patches<input type="radio" name="goodsKind" id="goodsKind" value="Patches">
</div>
<br/>
Subject:<br/>
<input type="text" name="title" style="width:100%;" />
<br/>
<br/>
TextArea:<br/>
<textarea name="txtarea" style="width:100%;" rows="30">
</textarea>

<center> <input type="submit" style="width:300px;" />
</center>
</form>

</div>






<?php
$type = $_POST["wheretopost"];
$title = $_POST["title"];
$body = $_POST["txtarea"];
$date = date("F j, Y");
?>


<?
$sql = "INSERT INTO `yoyo`.`posts` (`id`, `type`, `title`, `body`, `date`) VALUES (NULL, '$type', '$title', '$body', '$date');";
mysql_query($sql);

?>


</body>
</html>

请注意,它发布到的页面是它自己的页面。 (这可能是问题所在吗?)

最佳答案

在插入内容之前检查请求是否已发布:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$type = $_POST["wheretopost"];
$title = $_POST["title"];
$body = $_POST["txtarea"];
$date = date("F j, Y");

$sql = "INSERT INTO `yoyo`.`posts` (`id`, `type`, `title`, `body`, `date`) VALUES (NULL, '$type', '$title', '$body', '$date');";
mysql_query($sql);
}

关于php - 刷新或打开页面会将空数据插入我的数据库! PHP, 来自,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10860843/

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