Jump to content

register user - ADODB MS help needed


rich___

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

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

Link to comment
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

Link to comment
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''

Link to comment
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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.