rich___ Posted November 24, 2007 Share Posted November 24, 2007 hi, i want to make users able to register for my site using an access database, ive tried everything and nothing works. i want their info to be added to the database basically, so they can login <?php // creates a new connection object $adoCon = new COM("ADODB.Connection"); // opens the connection using a standard connection string $adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:/xampp/htdocs/xampp/db1.mdb"); // Receives values from Form, assigns values entered to vars $FirstName = $_POST["FirstName"]; $LastName = $_POST["LastName"]; $Username = $_POST["Username"]; $Password = $_POST["Password"]; // Declares SQL statement that will add data to the database $sSQL = "INSERT INTO tblUsers (FirstName, LastName, Username, Password) values ('$_POST[FirstName]', '$_POST[LastName]', '$_POST[username]', '$_POST[Password]')"; echo $sSQL; // Executes the SQL $adoCon->Execute($sSQL); ?> i get this error message: INSERT INTO tblUsers (FirstName, LastName, Username, Password) values ('s', 's', 's', 's') Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft JET Database Engine<br/><b>Description:</b> Syntax error in INSERT INTO statement.' in C:\xampp\htdocs\xampp\register.php:18 Stack trace: #0 C:\xampp\htdocs\xampp\register.php(18): com->Execute('INSERT INTO tbl...') #1 {main} thrown in C:\xampp\htdocs\xampp\register.php on line 18 Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/ Share on other sites More sharing options...
toplay Posted November 24, 2007 Share Posted November 24, 2007 I don't know about the DB you're using, but in MySQL "password" is a reserved word and hence the column name should be changed to something else or enclosed in backtick marks. Example: `Password` Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398308 Share on other sites More sharing options...
rich___ Posted November 24, 2007 Author Share Posted November 24, 2007 doesnt make a differnece :/ Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398352 Share on other sites More sharing options...
xyn Posted November 24, 2007 Share Posted November 24, 2007 this could be the problem values ('$_POST[FirstName]', '$_POST[LastName]', '$_POST[username]', '$_POST[Password]')"; change to values ('".$_POST[FirstName]."', '".$_POST[LastName]."', '".$_POST[username]."', '".$_POST[Password]."')"; Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398358 Share on other sites More sharing options...
rich___ Posted November 24, 2007 Author Share Posted November 24, 2007 i still get the same error : INSERT INTO tblUsers (FirstName, LastName, Username, Password) values ('test', 'test', 'test', 'test') Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft JET Database Engine<br/><b>Description:</b> Syntax error in INSERT INTO statement.' in C:\xampp\htdocs\xampp\register.php:22 Stack trace: #0 C:\xampp\htdocs\xampp\register.php(22): com->Execute('INSERT INTO tbl...') #1 {main} thrown in C:\xampp\htdocs\xampp\register.php on line 22 Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398368 Share on other sites More sharing options...
xyn Posted November 24, 2007 Share Posted November 24, 2007 well "Source: Microsoft JET Database Engine" Microsoft... no telling what the problem is. (my answer is i don't know. sorry.) Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398381 Share on other sites More sharing options...
rich___ Posted November 24, 2007 Author Share Posted November 24, 2007 ok so ive got the code to work without any errors, its just not writing to the database now, but it opens it, heres the code so far: <html> <head> </head> <body> <?php // Receives values from Form, assigns values entered to vars $sFirstName = $_POST["FirstName"]; $sLastName = $_POST["LastName"]; $sUsername = $_POST["Username"]; $sPassword = $_POST["Password"]; // creates a new connection object $adoCon = new COM("ADODB.Connection"); // opens the connection using a standard connection string try { $adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\xampp\\htdocs\\xampp\\db1.mdb"); } catch(Exception $e) { echo('Sorry - There was a problem with opening the database.<br />'); } // Declares SQL statement that will add data to the database try { $adoCon->Execute ( "INSERT INTO tblUsers (FirstName, LastName, Username, Password) VALUES ('$sFirstName', '$sLastName', '$sUsername', '$sPassword');" ); } catch(Exception $e) { echo ('Sorry - There was a problem with adding the data to the database.<br />'); } // closes the connection, frees up resources $adoCon->Close(); $adoCon = null; ?> </body> </html> any ideas? it just displays ''Sorry - There was a problem with adding the data to the database'' Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398397 Share on other sites More sharing options...
xyn Posted November 24, 2007 Share Posted November 24, 2007 your class hasn't been included neither started. you need include "path/to/class.php"; $adoCon = new ClassName; Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398398 Share on other sites More sharing options...
toplay Posted November 24, 2007 Share Posted November 24, 2007 You probably still have the same problem/error but you've masked it by utilizing a try/catch and not displaying the actual error. "Username" might also be a reserved word, so enclose column names in backtick marks in general. Anyway the error message is what it is...it thinks your insert syntax is not correct. I don't know about MS SQL syntax. Share what type of table and version you're trying to access so forum members can help you better. Double check the table and column names are correct. Make sure you don't have any hidden characters in query which could happen depending on what editor you used to create query (i.e. editing a UTF-8 file with editor that doesn't support UTF-. Copy the full displayed query and run it outside of PHP to see if row does indeed get inserted. ADO tutorial: http://www.w3schools.com/ado/default.asp Insert row tutorial page: http://www.w3schools.com/ado/ado_add.asp Try removing a layer and use ODBC functions directly: http://us2.php.net/manual/en/ref.uodbc.php Since this is more about a DB problem, I've moved this topic to the MS help area. Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398410 Share on other sites More sharing options...
rich___ Posted November 25, 2007 Author Share Posted November 25, 2007 im using access 2003 Link to comment https://forums.phpfreaks.com/topic/78707-register-user-adodb-ms-help-needed/#findComment-398450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.