admin管理员组文章数量:1122832
I'm simply trying to process data from an html form into my wordpress database through php. I've tried multiple times to get the data inserted but have had no luck.
The setup is as follows: Database name: seanmcve_AssociationNation Table: association The row I want data entered in: association_first_name
I've setup a page template called form_processing_template.php.
<?php
/*
Template Name: form processing template
*/
?>
<form action="" method="post">
<h4><strong>What is the legal name of your association?</strong></h4>
<input name="legalName" type="text" placeholder="Association Name" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
If($_POST['submit']) {
// run validation if you're not doing it in js
$legalname=$_POST['legalName'];
echo $legalname;
$wpdb->insert('association',
array(
'association_first_name' => '$legalname'
),
array(
'$s',
)
);
}
?>
<?php x_get_view( x_get_stack(), 'wp', 'page' ); ?>
I'm echoing the variable just to make sure it's correct and working (which is working) I've been referencing the wpdb class reference page and still have had no luck. Can anyone point me in the right direction?
I'm simply trying to process data from an html form into my wordpress database through php. I've tried multiple times to get the data inserted but have had no luck.
The setup is as follows: Database name: seanmcve_AssociationNation Table: association The row I want data entered in: association_first_name
I've setup a page template called form_processing_template.php.
<?php
/*
Template Name: form processing template
*/
?>
<form action="" method="post">
<h4><strong>What is the legal name of your association?</strong></h4>
<input name="legalName" type="text" placeholder="Association Name" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
If($_POST['submit']) {
// run validation if you're not doing it in js
$legalname=$_POST['legalName'];
echo $legalname;
$wpdb->insert('association',
array(
'association_first_name' => '$legalname'
),
array(
'$s',
)
);
}
?>
<?php x_get_view( x_get_stack(), 'wp', 'page' ); ?>
I'm echoing the variable just to make sure it's correct and working (which is working) I've been referencing the wpdb class reference page and still have had no luck. Can anyone point me in the right direction?
Share Improve this question asked Dec 3, 2015 at 19:44 Sean McVeySean McVey 113 bronze badges 1- do you have debugging enabled? – Milo Commented Dec 3, 2015 at 19:59
2 Answers
Reset to default 0I'm pretty sure you don't quote the $variable at all when doing a query with wpdb.
So 'association_first_name' => '$legalname'
would be 'association_first_name' => $legalname
But that might not solve all your problems.
global $wpdb;
$table_name = $wpdb->prefix . 'association';
$wpdb->insert($table_name,
array(
'association_first_name' => $legalname
),
array(
'%s',
)
);
You have multiple issues:
- Need to set table prefix
- You need to init $wpdb (global $wpdb)
- its %s not $s
- $legalname without ''
Use the Snippet above to handle the insert part
本文标签: mysqlProcessing forms with php to wordpress database
版权声明:本文标题:mysql - Processing forms with php to wordpress database 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303142a1931781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论