Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT erring? 2

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
does anything look wrong with this?

Code:
$mail_name =  $_POST["name"];
$mail_email = $_POST["email"];
$mail_birthday = $_POST["birthday"];

//echo $_ENV["SCRIPT_FILENAME"];

$dbLocation = "d:\websites\mysite\admin\data.mdb;";
$conn = new COM ("ADODB.Connection") or die( "Cannot start ADO" ); 
$conn->Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$dbLocation );
$sSQL = "insert into tbl_mailing_list (email_birthday,email_address,email_name) values ('$mail_birthday','$mail_email','$mail_name')";
echo $sSQL
$conn->Execute( $sSQL );
$conn->Close(); 
$conn->Release();

If I comment out these lines:
//$conn->Execute( $sSQL ); //Execute SQL query
//$conn->Close(); //Close database connection
//$conn->Release(); //Release resources for this

sSQL echoes out. If I uncomment them, nothing happens: no error, no insert...

Sorry for the rudimentary post. I'm mostly unfamiliar with PHP.
 
I'll ask a question from a linux perspective which may apply to your Win case - do you have sufficient user rights (as the user/account running the script) to perform this action against the database?

D.E.R. Management - IT Project Management Consulting
 
Yeah, permissions were fine. It's very odd. If I comment out the echo and the release, it works. Uncomment the echo, nothing. I don't understand. Why can't I echo?

Code:
$dbLocation = "d:\websites\somesite\admin\data.mdb;";
$conn = new COM ("ADODB.Connection") or die( "Cannot start ADO" ); 
$conn->Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$dbLocation ); 
$sSQL = "insert into tbl_mailing_list (email_birthday,email_address,email_name) values ('$mail_birthday','$mail_email','$mail_name')";
//echo $sSQL
$conn->Execute( $sSQL );
$conn->Close(); 
//$conn->Release();
 
It appears that you have missed semicolon in your echo statement i.e.echo $sSQL


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Agreed. your echo statement is missing a ";" at the end.
You should be getting an error. How is your display_error directive set in your PHP.ini?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ah, that semicolon. Seems to have fixed it.

I don't have control of the .ini file; it is on a third-party host. I thought there was a way to set error messages in a page, but that wasn't working either.

I do get an error if I try and release the connection. Is it important to release, or is closing enough? Forgive my ignorance; I'm more familiar with vbs.
Code:
Fatal error: Uncaught exception 'com_exception' with message 'Source: ADODB.Connection
Description: Operation is not allowed when the object is closed.' in d:\websites\somesite\text\mlist.php:29 Stack trace: #0 d:\websites\somesite\text\mlist.php(29): com->Release() #1 {main} thrown in d:\websites\somesite\text\mlist.php on line 29
 
If its already closed its already been released. but its really not necessary to close it, as it will automatically close when the page is changed or the browser window closed.

You may want to close it if you queried large amounts of data from the DB and don't want to bog down server resources otherwise letting PHP handle it is o.k.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top