Jump to content

Archived

This topic is now archived and is closed to further replies.

rich___

register user - ADODB MS help needed

Recommended Posts

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

Share this post


Link to post
Share on other sites

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`

 

 

 

 

Share this post


Link to post
Share on other sites

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]."')";

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

well "Source: Microsoft JET Database Engine" Microsoft...

no telling what the problem is.

(my answer is i don't know. sorry.)

Share this post


Link to post
Share on other sites

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''

Share this post


Link to post
Share on other sites

your class hasn't been included

neither started.

 

you need

include "path/to/class.php";

$adoCon = new ClassName;

Share this post


Link to post
Share on other sites

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-8). 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.

 

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.