Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,462 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,354 people online right now. Registration is fast and FREE... Join Now!




Inserting Data Into A Database

 
Reply to this topicStart new topic

Inserting Data Into A Database

bexlhoward1
post 11 Mar, 2005 - 09:15 AM
Post #1


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

Hi Guys,

I need to insert a piece of data into a Access (I know dont say its crap!) database. I am using sessions and the username at present is stored in the session. A variable named $id is passed in the URL. I need this variable to be sent to the database when the user accesses the page. The SQL I am using is:

$strSQL = "INSERT INTO user (id) values ('$id') WHERE username = '".$username."'";

I probably have a minor error but as I am knew to all this I cannot figure it out! Any help please.

Thanks.

Bex.
User is offlineProfile CardPM

Go to the top of the page

cyberscribe
post 11 Mar, 2005 - 04:34 PM
Post #2


humble.genius

Group Icon
Joined: 5 May, 2002
Posts: 1,062



Thanked 2 times

Dream Kudos: 154
My Contributions


If $id is numeric you don't need quotes. You can also use the syntax:
CODE

insert into foo set bar=$baz

to make it easier when you have 4,000 columns and don't want to keep track of how many commas you used in the values statement.
User is offlineProfile CardPM

Go to the top of the page

bexlhoward1
post 12 Mar, 2005 - 05:24 AM
Post #3


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

I dont really understand the reply! The problem I am having is that I can insert the data but I cannot get it to write in the correct place. I want to add a WHERE statement but I get errors.

Thanks.
User is offlineProfile CardPM

Go to the top of the page

bexlhoward1
post 12 Mar, 2005 - 05:30 AM
Post #4


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

Do you somehow think I should use UPDATE?

Thanks.
User is offlineProfile CardPM

Go to the top of the page

bexlhoward1
post 12 Mar, 2005 - 05:43 AM
Post #5


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

I have tried:

CODE
$strSQL = "UPDATE flights SET user_id = '$user_id->value' WHERE flight_id = '$id'";


but I cannot get this to work.
User is offlineProfile CardPM

Go to the top of the page

bexlhoward1
post 12 Mar, 2005 - 10:50 AM
Post #6


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

not to worry, ive done it!
User is offlineProfile CardPM

Go to the top of the page

cyberscribe
post 13 Mar, 2005 - 12:30 AM
Post #7


humble.genius

Group Icon
Joined: 5 May, 2002
Posts: 1,062



Thanked 2 times

Dream Kudos: 154
My Contributions


Cool. Did removing the quotes fix the problem?
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:08PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month