我正在尝试使用以下 HTML 创建成功的更新:
<form id="form2" name="form2" method="post"
onsubmit="return validateForm();" action="">
Id <input type="text" class="txt" name="id" />
<br />
Name <input type="text" class="txt" name="name" />
<br />
Website <input type="text" class="txt" name="website" />
<br />
Description <input type="text" class="txt" name="description" />
<br />
<input type="submit" id="submit" value="Submit"/>
</form>
然后我使用以下 PHP 读取值并更新我的数据库:
<?php
global $wpdb;
if (isset($_GET['id']) && !empty($_GET['id']) &&
isset($_POST['name']) && !empty($_POST['name']) &&
isset($_POST['website']) && !empty($_POST['website']) &&
isset($_POST['description']) && !empty($_POST['description']))
{
$wpdb->query("update where id = $_GET['id'] ".PRO_TABLE_PREFIX
."tutorial (name, website, description) "
."values('{$_POST['name']}', '{$_POST['website']}', '{$_POST['description']}')");
}
?>
我做错了什么?
最佳答案
<form id="form2" name="form2" **method="post"** onsubmit="return validateForm();" action="">
请注意你的表单方法是post
并且您正在尝试使用 get 方法获取数据
isset ( $_GET['id'] ) && !空 ( $_GET['id'] )
将它们替换为 $_POST['key_name]; 以获得正确的结果。
关于php - 更新 id = $GET ['id' ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14108281/