My client want to have form collecting the user data and save to external database
that is on different hosting of the wordpress site.
I need to have two forms, one is for contact us purpose and the second for newsletter registering.
Both forms need to collect the data and save it to the database on different tables.
I found plugin that let me make form on wordpress and plugin that let my save the data on the database wordpress use, but this in not what I need.
I found this solution Create a form and save data in a external DB with Wordpress but it do not help me.
I tried to run some PHP code (and learn it this way, because I do not know php) to get the data but I got nothing.
it is possible to do what I am asking?
Is there some plugin to do this?
I do not ask for code, but some help will great.
Thanks
The code in this page helps you create a second database connection, once you connect the second database, you can store data to it using routine WordPress database commands
http://bavotasan.com/2011/access-another-database-in-wordpress/
$newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
$newdb->show_errors();
Hope this helps, let me know if there is still an issue.
Related
I am creating a website audit tool now in this someone will insert details of their website and answer some questions and i am inserting that in the database. Now I want to show results in new page according to the choices user makes now how can I get the details of that inserted data instantly any way to get that through PHP?
Yes, the same way you would normally get data. When loading the new page, have your controller load the data and then include it.
If this is asynchronous or doesn't include a page refresh, then you could handle this more quickly with JavaScript.
I am creating a site and i am making a general option page for the site that include the site name, logo, social links so that i can manage them dynamically from one place without changing the links and text in all pages where i called them.
What I want is that the table i created in database, i want to have only one row in it. If someone try to add other row of data it should not be added because i have to call only one data for the site.
I hope the query is clear to all.
Thanks for your support. Help me if u can. please :)
By,
if someone try to add other row of data it should not be added
what do you mean? Are you trying to avoid unauthorized access? If yes, then you need to implement roles https://laracasts.com/discuss/channels/general-discussion/roles-and-permissions-in-laravel-5
To manage your site information, I'm sure you set a form that will be used to update the site info. And from the look of things you will only be updating that row when you hit save or update button. I don't think you will be doing full CRUD here just updating so there'll be no chance of inserting a new row of data in the db.
So three things:
you want to create a migration, seed the table with the site details accordingly. run the migration
you want to make sure the user trying to access this route is authorized to do so
you want to pre populate the site info in the form fields when the edit site info page loads and you want to save the form when the authorized user changes any of the site info
This way, there'll be no question of stopping further insertions into the db.
I want to add a new page by my plugin.I tried a lot but failed.
What is the hook for creating a new page?Please help.
function add_new_page(){
.....
}
action('init','add_new_page');
If I understood properly, you want to create a new record in the database that is a page. If indeed this is the case, you need to programatically add a new POST of type PAGE (yeah, it is a bit confusing).
To this, you will setup an associative array with the details of your post and use the wp_save_post function, that is here: http://codex.wordpress.org/Function_Reference/wp_insert_post.
Just remember to check if your page already exists before inserting again, or it will create thousands of pages.
If you know all the tables then just write directly to the database for new page creation.
here is the help link http://codex.wordpress.org/Function_Reference/wp_insert_post
I'm having some trouble implementing a bit of custom functionality in the Contact Form 7 plugin for Wordpress.
What I want to do is pretty straightforward. The contact form in question is a normal contact inquiry form, so I need to retain the usual functionality (mailing the data). However I also have a checkbox on the form that allows the sender to choose whether to subscribe to the client's mailing list in addition to mailing the contact inquiry.
The client uses Bronto for their mass mailing (similar to CC or Mailchimp). Bronto has a "direct add" feature (more info here) that allows you to send parameters to add contacts to the Bronto account by embedding an image whose url contains the requisite parameters (email address, list to subscribe to, etc).
I can construct the image url with the contact form parameters no problem, but actually getting the image request sent is a different matter. I am over my head both in PHP and JS here and not sure what course to take.
Currently I'm using the wpcf7_before_send_mail php hook built into CF7 and this appears to allow me to collect the form data and build the URL. However, since the plugin uses AJAX and doesn't actually redirect to another page on form submission it seems I can't successfully use any kind of php output (echo, alert, even error_log), presumably because the server doesn't know what it's supposed to write to.
In functions.php:
add_action( 'wpcf7_before_send_mail', 'bronto_contact_add' );
function bronto_contact_add( $cf7 ) {
$emailcf = $cf7->posted_data['email'];
echo $emailcf;
}
This is just a test to see if echo works - it does not. Instead the form just hangs on submission and I see the rotating loading gif forever.
What I need to do is build the image url using parameters from the cf7 object (which I can do no problem) and then somehow send that image request to the Bronto server (this is the part I am confused about). If this was a normal form that redirected to another php page upon submission I would have no problem doing this at all, but it uses AJAX which I don't know much about so I'm pretty lost now.
Can anybody help shed some light on how the best way to accomplish this might be?
If the submit is hanging after you attached your function, at least you know that it had an effect. I'm not terribly familiar with Contact Forms 7, but this is probably not the proper place for an echo, and my guess is that it is hanging because you are writing to the buffer and then it is trying to do a redirect (check your error logs). If you want to see the contents of $cf7, a better way to do it would be:
// first option, using print_r()
error_log(print_r($cf7, true));
// second option, using var_dump() if you need the additional output
ob_start(); // start buffer capture
var_dump($cf7); // dump the values
$contents = ob_get_contents(); // put the buffer into a variable
ob_end_clean(); // end capture
error_log($contents); // log contents of $cf7
The contents of the $cf7 variable will then be in your PHP error log, which will tell you how to access the different components.
I came across your thread while looking for a similar solution to the same problem with CF7 - a hang on submission when trying to pass info to my own database on the back-end for a CRM.
I did not see an answer to this issue anywhere on the web in relation to CF7 integration, so thought I would post here what I found was the problem and how it was fixed. I'm no pro, but the solution works in testing, if anyone has anything to add to this solution please chime in
Basically, if you are using Wordpress and trying to pass the info into a CRM database, I am going to assume your database tables are not on the same database as your Wordpress site database. What you are then trying to do is establish two database connections simultaneously, but the reference ID is being reused for your Wordpress database when trying to connect to your CRM. I found this was the root cause of the hang on submission during testing.
I used a deprecated command from PHP 4 that still works in PHP 5, mysql_connect, :
mysql_connect('localhost', 'root', '', true);
By passing 'true' as your fourth parameter you are able to keep the connection separate from the one running for your Wordpress site. Did this and the CF7 submission doesn't hang, it submits to the CRM and sends it out as an e-mail simultaneously, no problem.
Note too though, if something is wrong with your syntax for the CRM data submission i.e. misnamed variable, etc.. it will also hang. If passing 'true' doesn't work check your code first to make sure it's clean.
If anyone reading this has an equivalent solution for this with 'mysqli' commands I'd be interested to know it, I tried it using mysqli and couldn't get it working.
Is there some reason why you can't just prefix the table names and add them to the same database? It seems that would be a better solution and would work fine with mysqli as opposed to using archaic, insecure drivers.....
I guess, I just don't see the point of using two databases in this case... I would try using one.
Every user that signs up for the site is given a user id (stored in the database as User_ID), I am using userCake for the login/user management system just to clarify.
I am quite new to MySQL and PHP. I am trying to create a way so that a user can input a link into a form (I have the form created) and then it saves that to the database (new table?). How would I go about;
Creating the table structure for that.?
Posting the URL to the database.?
Retrieving all of the links associated with the User ID.?
Displaying all the users links in a list (a list just for testing)?
I have looked around for some time but can't seem to find anything that helps. All help is greatly appreciated.
i think maybe http://www.sitepoint.com/getting-started-mysql/
other resources are available, I tried "beginning database driven php website" in fav search engine and there is tons and tons of the stuff, i dont think the actual teaching etc can be done in a single post on SO and maybe you should learn to create tables, and query them with a query tool. once you got that you can then do your first php hello world app. create a hello world form then finally hook up database and start then looking at DB security etc.