Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5530

billibones on "How to write to a database NOT the wordpress database"

$
0
0

Liek Dan said it is best to stay within the WP Db, however easiest way to do what you are wanting to do is to create a file called somthing like: db_connect.php (have all your connections to your DB here (ie. db_name, host, user, pass)

Then (if using a WordPress generated page to collect your users information, you will want to use a plugin like [include it] or create a custom template page based on your theme with your contact form inside of it and make your calls normally as if it were a standard PHP file.)

Something like this:

<? include db_connect.php;

// php / mysql to process collected data
if (isset($formSubmitted))
{
$name = $_POST['name']
$othervariables = $_POST['othervariables'];
$query = 'INSERT ..... $name, $othervariables';
$result = mysql_query($query);
}

// user contact form to collect data
echo 'your form stuff';
-- Note: make sure you write back to the same page by calling:
<form action='<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>' method='POST' enctype='application/x-www-form-urlencoded'>
form submit / clear <inputs>
<input type='hidden' name'formSubmitted' value='Y'>
</form>

?>

Hope this helps.


Viewing all articles
Browse latest Browse all 5530

Trending Articles