AlguienEnEsteMundo
AlguienEnEsteMundo

Reputation: 123

Insert data in mysql from contact form 7 using wordpress

I, trying to insert data from my contact form 7 to mysql using wordpress.

So for that I create a basic contact form:

<p>Your Name (required)<br />
[text* name:sName ] </p>

<p>Your Email (required)<br />
[email* name:sEmail] </p>

<input type="submit" name:submit>

This is the php function:

<?php 
require_once('../../../wp-load.php');
include ('../../../wp-config.php');
global $wpdb;    
if(isset($_POST['submit']))
{
$name=addslashes($_POST['sName']);
$email=addslashes($_POST['sEmail']);
$wpdb->insert("Users",array(
"sName"=>$name,
"sEmail"=>$email,
));
}    
$wpdb->show_errors();
?>

And the Page:

<form action="/wp-content/plugins/my-codes/insertUser.php" method="post">
[contact-form-7 id="11" title="Contact form 1"]
</form>

So far I know that the php function works, and that I have connection to the data base, because if instead of using the contact form 7 I use the following code in the page (see below), it insert the information perfectly

<form action="/wp-content/plugins/my-codes/insertUser.php" method="post">
Name: <input type="text" name="sName" />
Email: <input type="text" name="sEmail" />
<input type="submit" name="submit">
</form>

So I know that the problem is coming somewhere from the contact form, but I cant see what Im doing wrong. Any idea?

Thanks!

Upvotes: 1

Views: 1632

Answers (1)

AlguienEnEsteMundo
AlguienEnEsteMundo

Reputation: 123

This is the proper way of doing it:

<p>Your Name (required)<br /> </p>
[text* sName id:sName]

<p>Your Email (required)<br /></p>
[email* sEmail id:sEmail] 

<input type="submit" name="submit">

Upvotes: 1

Related Questions