Link to home
Start Free TrialLog in
Avatar of kgerb
kgerbFlag for United States of America

asked on

Logging Form Data to Access Database Using PHP

Hello Everyone,
I'm trying to finish up the development on my first website.  I've been working on this for a few weeks now (when I have time) and I have received very valuable help from Ray and Marco.  Here are some of the previous threads if you're interested.  

Here, Here, and Here

Initially I wanted the "contact me" form to send me an email on Submit.  Ray recommended I change my approach and log the data into a database instead.  That way I don't have to worry about ISP's catching my emails in their spam filters.  So that's what I did.  Here is my problem.

Everything was working fine on my localhost but when I uploaded my site to the GoDaddy server it doesn't work anymore.


When I initially uploaded the new site to the GoDaddy server I received an error saying some driver was not installed.  I googled for a while and found the Select PHP Version manager in the cPanel.
User generated imageThis link takes you to another screen where you can select whatever options (or drivers?) you want to install (I think).  Honestly, I don't really know what it does when you check one of the boxes.
User generated image
I checked the "pdo_odbc" box.  I did this b/c I needed to uncomment the "extension=php_pdo_odbc.dll" line in my php.ini file in order to get it work work on my local host.  

So, now when I click the submit button I don't get the error about the missing driver anymore.  Now the submit button does nothing.   I called GoDaddy tech support and they couldn't help me but they did tell me a few things that might be the problem.

1.  They said I may need to add a User.ini file to my root directory in order to make the necessary settings for the PHP to work correctly.  No idea what this means.
2.  They said Access databases are not supported on the type of server I have.  They said I have to use a mySQL database.  Can that be true!  Why is it working on my local machine?

Here is a snippet from my JS file where I make the $_Post call.
if(hasError == false) {
	$.post("PHP/log_contact.php", {frmName: nameVal, frmEmail: emailVal, frmMessage: messageVal}, 
		function(data) {
			window.alert(data);
			document.getElementById("msgSuccess").style.display = "block";
			resetFormInput();
		}
	);
}

Open in new window

Here is my entire PHP file
<?php
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');

$dbName = $_SERVER["DOCUMENT_ROOT"] . "/GerberEngineering/dbFolder/ContactLog.accdb";	//For local testing
//$dbName = $_SERVER["DOCUMENT_ROOT"] . "/dbFolder/ContactLog.accdb";					//For use on GoDaddy server
$connStr = "odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" . $dbName . ";";

echo $dbName;

if (!file_exists($dbName)) {
    die("Could not find database file.");
}

$db = new PDO($connStr);

$strName = $_POST['frmName'];
$strEmail = $_POST['frmEmail'];
$strMessage = $_POST['frmMessage'];
$Date = date('Y-m-d H:i:s');

$sql  = "INSERT INTO ContactLog";
$sql .= " (ContactName, Email, Message, ContactDate)";
$sql .= " VALUES ('" . $strName . "', '" . $strEmail . "', '" . $strMessage . "', '" . $Date . "')";

$db->query($sql);

?>

Open in new window

I know this is a difficult problem since it is dealing with a specific web host but I would appreciate any help I could get.  If you need me to upload any other files I can definitely do that.

Kyle
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kgerb

ASKER

Thanks everyone for your answers.  I'm in the process of converting the database to mySQL.  Really there's no conversion.  There's only one table.  But, I've never used mySQL before so I'm sure I'll be posting again when I get stuck.  

Oh, and Ray, next time don't hold back.  Tell me how you really feel! :-)

Thanks again,
Kyle