473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

inserting data from form to database help

hi im wondering is anyone can help me with this peice of code

what i am trying todo is to create a register page where users type information which goes into a database heres the code

[b]FORM CODE [B/]

[HTML]
<html>
<head>
<title>Signup Form</title>
</head>
<body>
<form name=form1 method=post action=register.php>
<table width=100% border=0 cellpadding=4 cellspacing=0>
<tr>
<td width=24% align=left valign=top>First Name</td>
<td width=76%><input name=first_name type=text id=first_name2></td>
</tr>
<tr>
<td align=left valign=top>Last Name</td>
<td><input name=last_name type=text id=last_name></td>
</tr>
<tr>
<td align=left valign=top>Email Address</td>
<td><input name=email_address type=text id=email_address></td>
</tr>
<tr>
<td align=left valign=top>Desired Username</td>
<td><input name=username type=text id=username></td>
</tr>
<tr>
<td align=left valign=top>Information about you:</td>
<td><textarea name=password id=password></textarea></td> </tr>
<tr>
<td align=left valign=top> </td>
<td><input type=submit name=Submit value=Join Now!></td>
</tr>
</table>
</form>
</body>
</html>
[/HTML]

DATABASE CODE register.php

[PHP]
<?php

// creates a new connection object
$adoCon = new COM("ADODB.Connection");

// opens the connection using a standard Access connection string
$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\wamp\www\PRU.mdb");

{ $adoCon->Execute
( "INSERT INTO tblUsers
(firstname,lastName,email,username,password)
VALUES
('$_POST[first_name]','$_POST[last_name]','$_POST[email_address]','$_POST[username]','$_POST[password]');"
);
}

// closes the connection, frees up resources, kills all traces
$adoCon->Close();
$adoCon = null;

{ adocon

?>
[/PHP]

and heres the error message after pressing the submit button

Parse error: parse error, unexpected $end in C:\wamp\www\pru\register.php on line 23
Nov 15 '06 #1
13 2343
ronverdonk
4,258 Expert 4TB
You specify an opening curly brace at [php]{ adocon[/php] but where is the closing curly brace?

Ronald :cool:
Nov 15 '06 #2
You specify an opening curly brace at [php]{ adocon[/php] but where is the closing curly brace?

Ronald :cool:
ive taken this off and and it still says the same error

line 23 is the end of th php code i unsure whtas happening nothing is been added to the databse and i assume if the conection code was wrong it would throw up cant connect to database etc
Nov 15 '06 #3
ronverdonk
4,258 Expert 4TB
And what is the function of the other curly braces as in [php]{ $adoCon->Execute[/php] and at the end of the insert? Those do not belong to any PHP statement in your code.

Ronald :cool:
Nov 15 '06 #4
And what is the function of the other curly braces as in [php]{ $adoCon->Execute[/php] and at the end of the insert? Those do not belong to any PHP statement in your code.

Ronald :cool:
i was taught to put those in anyways ive taken them out can anyone see anyother fundamental problems on why this code isnt working

my thoughts think its todo with not having a session but surley the $post gives the information from the form to register.php

or if anyone knows another way of adding information into a database from a form using php could give an example i would apricate it greatly thnx guys
Nov 15 '06 #5
How about this? (removed the last line with adocon... that made little sense)
[PHP]
<?php

// creates a new connection object
$adoCon = new COM("ADODB.Connection");

// opens the connection using a standard Access connection string
$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\wamp\www\PRU.mdb");

$adoCon->Execute(
"INSERT INTO tblUsers(firstname,lastName,email,username,passwor d) VALUES
('$_POST[first_name]','$_POST[last_name]','$_POST[email_address]',
'$_POST[username]','$_POST[password]');"
);

// closes the connection, frees up resources, kills all traces
$adoCon->Close();
$adoCon = null;

?> [/PHP]
Nov 15 '06 #6
ive corected and tidyed up my code to

[PHP]
<?php
$first = $_POST['first_name'];
$last = $_POST['last_name'];
$email = $_POST['email_address'];
$user = $_POST['username'];
$password = $_POST['password'];

// creates a new connection object
$adoCon = new COM("ADODB.Connection");

// opens the connection using a standard Access connection string
$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\wamp\www\pru\PRU.mdb");

$adoCon->Execute
( "INSERT INTO tblusers
(firstname,lastName,email,username,password)
VALUES
('$first','$last','$email','$user','$password');"

);


// closes the recordset, frees up resources, kills all traces
$adocon->Close();
$adocon->Release();

?>

[/PHP]

now i am getting this error message whihc i assume means there is something wrong with the insert statment

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:\wamp\www\pru\register2.php:20 Stack trace: #0 C:\wamp\www\pru\register2.php(20): com->Execute('INSERT INTO tbl...') #1 {main} thrown in C:\wamp\www\pru\register2.php on line 20
Nov 15 '06 #7
The problem is that you do some tasks, which one might call risky or unstable... Like database connections: the connection might be refused, the credentials might be wrong, whatever...
Instead of letting an application just crash when something goes wrong, we want to "catch" the error, and act accordingly (displaying an error message, log the error, whatever...). Usually that is achieved by something called a try/catch block.

Haven't been using PHP since some pre PHP5 version, so im not that aware of the exact syntax used for try/catch in php...

Read up on that here:
http://www.phpfreaks.com/phpmanual/page/language.exceptions.html
Nov 15 '06 #8
Maybe i should have read all of your error :)

Something's wrong in your query too...
Nov 15 '06 #9
ive added a catch on the insert and have got this message shooting back at me lol ive spent hours looking at this code it has to be soemthing simple

[PHP]
<?php
$id = 90;
$first = $_POST['first_name'];
$last = $_POST['last_name'];
$email = $_POST['email_address'];
$user = $_POST['username'];
$password = $_POST['password'];

// creates a new connection object
$adoCon = new COM("ADODB.Connection");

// opens the connection using a standard Access connection string
$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\wamp\www\pru\PRU.mdb");

{$adoCon->Execute
( "INSERT INTO tblusers
(id,firstname,lastName,email,username,password)
VALUES
($id,'$first','$last','$email','$user','$password' );"

);
}
catch(exception $e)
{ echo 'sorry - there was a problem with adding data to the databse.<br />';
}

// closes the recordset, frees up resources, kills all traces
$adocon->Close();
$adocon->Release();

?>


[/PHP]

Parse error: parse error, unexpected T_CATCH in C:\wamp\www\pru\register.php on line 23
Nov 15 '06 #10
ronverdonk
4,258 Expert 4TB
Where is the TRY block in your code gone to??

Ronald :cool:
Nov 15 '06 #11
lol what does that mean :)

i think i gonna move onto coding the next part and see if i cant figure out whats oing on tomorow
Nov 15 '06 #12
Change
{$adoCon->Execute
To

try {

$adoCon->Execute


a try cant exist without a catch and vice versa.
Nov 16 '06 #13
steven
143 100+
Firstly, I would start by reading some of the basics on php.net

The online manual is unbelievably useful and will contain most of the answers to questions like these.

For example, you can't just catch an error. You have to "try" something first. So you would do

Expand|Select|Wrap|Line Numbers
  1. try {
  2.   //code to try
  3. } catch (Exception $e)
  4.   //catch error, display $e or just carry on with another try/catch block
  5. }
  6.  
The best thing to do is echo your SQL statement during runtime, see if it looks okay, then copy and paste it intop the database prompt and see if it works directly with your Database engine.

Also, before trying to do your INSERT statements, attempt to see if the connection was successful. See if you have a resource id in the connection variable.
Nov 16 '06 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Geoff Wickens | last post by:
I am quite new to all this but am trying to create a database driven site. I have been able to use information from my sample database but I now want to be able to insert data into it. At present I...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
4
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
0
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
25
by: bseakgano | last post by:
I have developed a intranet . Using HTML , SQL and ASP . I have created a table with SQL is just fine . And design a form is just looks fine to me . But when I try to insert Data into the SQL I just...
2
by: Ravigandha | last post by:
Hello everybody, My question is how to insert special characters and symbols in Mysql5 database and how to retrieve them from database in php. Here i am inserting some data from a form,by post...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
18
by: boss1 | last post by:
Hi all, i m having a problem with inserting data in oracle db. When i use form action =(call self page) then data is inserting properly.But problem with when using form...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.