Php 注册插件时没有错误,仍然不更新wordpress表
这是我的插件,它让我发疯。。。它在激活时创建一个新表,但之后不会插入或更新数据,并且页面上没有错误。。请帮忙 包括Php 注册插件时没有错误,仍然不更新wordpress表,php,database,plugins,wordpress,Php,Database,Plugins,Wordpress,这是我的插件,它让我发疯。。。它在激活时创建一个新表,但之后不会插入或更新数据,并且页面上没有错误。。请帮忙 包括 <?php wp_register_style( 'andreiplugin', plugin_dir_url( FILE ) . 'pluginAndrei.css' ); register_activation_hook(__FILE__, 'andreiPlugin_table'); 表格功能:
<?php
wp_register_style( 'andreiplugin', plugin_dir_url( FILE ) . 'pluginAndrei.css' );
register_activation_hook(__FILE__, 'andreiPlugin_table');
表格功能:
function userForm(){
$name = $_POST['username'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$insert = 1;
global $wpdb;
$result_db_table = $wpdb->prefix . "myusers";
$query_data = $wpdb->get_results($wpdb->prepare("
SELECT *
FROM " .$result_db_table, OBJECT ));
while ($query_data) {
if($name == $query_data['name']){
$insert = 0;
$wpdb->update(
'$table_name',
array(
'name' => '$name',
'email' => '$email',
'gender' => '$gender'
));
}
}
if($insert==1){
$wpdb->insert(
'$result_db_table',
array(
'name' => '$name',
'email' => '$email',
'gender' => '$gender'
));
}
}
?>
我还将html包含在插件中
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>formsubmit</title>
提交表格
并用javascript进行了表单验证
<script type="text/javascript">
function check_info(){
var username = document.getElementById('username').value;
var email = document.getElementById('email').value;
var male = document.getElementById('auto_renew_male').checked;
var female = document.getElementById('auto_renew_female').checked;
if (male==false&&female==false) {
alert('Please specify your gender');
return false;
}
if (username==""|| email=="") {
alert('Please fill in all fields')
return false;
}
else{
return true;
}
}
</script>
</head>
<body>
<div id="wrapper"> <!--style="float:left; margin-left: 300px;"-->
函数检查信息(){
var username=document.getElementById('username')。值;
var email=document.getElementById('email')。值;
var male=document.getElementById('auto_renew_male')。选中;
var female=document.getElementById('auto_renew_female')。选中;
if(男性==false&女性==false){
警告(“请指定您的性别”);
返回false;
}
如果(用户名=“”| |电子邮件=“”){
警报('请填写所有字段')
返回false;
}
否则{
返回true;
}
}
和。。形式本身
<form action="" method="post" onsubmit="return check_info();">
<p>Full Name:</p><input type="text" name="username" id="username"/>
<p>Email:</p><input type="text" name="email" id="email"/>
<p>What is your gender</p>
Male<input type="radio" name="gender" value="male" id="auto_renew_male"><br/>
Female<input type="radio" name="gender" value="female" id="auto_renew_female"><br/>
<input type="submit" value="login" name="submitButton"/>
</form>
</div>
</body>
</html>
全名:
电邮:
你的性别是什么
男性
女性
最后,我在这里执行userForm函数。。我尝试通过userForm()在if()之后调用它;还是没有效果。。。按下按钮后,它也会回响“谢谢…”
<?php
if(isset($_POST['submitButton'])){
register_activation_hook(__FILE__, 'userForm');
echo "Thank you for your submission!";
}
?>
您的配置文件中是否设置了
define('WP\u DEBUG',true)
设置?注意:WP\u register\u样式被错误地调用了。在wp\u enqueue\u脚本
、admin\u enqueue\u脚本
、或login\u enqueue\u脚本
挂钩之前,不应注册或排队脚本和样式。有关更多信息,请参阅WordPress中的。(此消息是在版本3.3中添加的。)在E:\apps\wamp\wamp\www\wordpress\wordpress\wp includes\functions.php的第3560行
<?php
if(isset($_POST['submitButton'])){
register_activation_hook(__FILE__, 'userForm');
echo "Thank you for your submission!";
}
?>