Jump to content

adding data to mysql


lmcgr44

Recommended Posts

hey everyone!

 

in new to the whole php and mysql thing and i am stuck with one part, i have got a login script, once loged in it takes them to there account page, on there account page they can added data into there file, to mysql, so what I'm looking for is how to add the username they logged in with to be added into the database with the rest of the information they just submitted, so when they go to retrieve there information into a table they will only get the information that has there username with it.

 

as much help as possible would be great!

 

thank-you

Link to comment
Share on other sites

It'll be a lot easier to use a session and select all the information you want from the database using some form if ID which is unique to the person logged in.

 

ok then how can i accomplish that? can you show me somewhere on the internet that can explain and show me how?

 

thank-you

Link to comment
Share on other sites

Any links given to you about login scripts will most probably contain a load of crap which you don't need to understand for your problem.

 

All you need to do is authenticate the user when they submit the login form. Then create a session called something like "username" and assign the username they logged in with as the value.

 

Every time they go on to a new page you can then run a function or something to retrieve all their details from the database.

 

If you don't know what I mean by session look up sessions via google... else we could be here for hours giving you links and trying to explain everything to you.

Link to comment
Share on other sites

Any links given to you about login scripts will most probably contain a load of crap which you don't need to understand for your problem.

 

All you need to do is authenticate the user when they submit the login form. Then create a session called something like "username" and assign the username they logged in with as the value.

 

Every time they go on to a new page you can then run a function or something to retrieve all their details from the database.

 

If you don't know what I mean by session look up sessions via google... else we could be here for hours giving you links and trying to explain everything to you.

 

yes I'm pretty sure i know what you mean, at the top of my pages i have

 

if (isset($_SESSION['user_id']))

 

is that what you mean? if so how do i submit the user_id to the database with the form that is being submitted?

 

 

Link to comment
Share on other sites

Aye? If they're logged in and you've got the user ID in a session already, just use that to query the database with a simple select T-SQL statement...

 

I'm sorry like i said I'm new to this, i still do not understand what u mean by that?

Link to comment
Share on other sites

It's quite apparent to me you know very little and have a minimal understanding of the language and how to get data from a database.

 

Before trying to create a login script which is probably quite advanced for you, go and learn how to successfully retrieve data from a database and how to create/destroy/manage PHP sessions...

 

We can't lecture on these topics due to their wide scope. You will need to do the research yourself. Start with google and anything you don't understand specifically, google as well. Just don't stray to far from your objective.

Link to comment
Share on other sites

It's quite apparent to me you know very little and have a minimal understanding of the language and how to get data from a database.

 

Before trying to create a login script which is probably quite advanced for you, go and learn how to successfully retrieve data from a database and how to create/destroy/manage PHP sessions...

 

We can't lecture on these topics due to their wide scope. You will need to do the research yourself. Start with google and anything you don't understand specifically, google as well. Just don't stray to far from your objective.

 

ok i have already got my login script set up, i have the add form to database already set up, i also have a table set up retrieving the data from the database, the only thing i can't work out how to do is the add data into the database that is specific to a user and then retrieve that data for that user when he logged in, so know else can view other peoples data, the whole point of me being on here is for help, and that is the point of this forum. am i rite?

Link to comment
Share on other sites

Your absolutely right. We're here to help but you're confusing everything.

 

Your OP says in summary:

 

The user logs in -> Log in information stored in database -> User goes to account page -> Users adds more information which is added to the database -> You try to add the username they just logged in with to the database with the information they just submitted?

 

That doesn't make sense. You should register a user and they will have perhaps the basic details (Username, Email, Password). They login and are taken to a personalised page where they can enter additional information (E.g. information for their profile). This information is then stored in the database in the same table as their username, email and password using an UPDATE T-SQL statement...

 

I'm not trying to be rude I'm trying to help but no-one can help you if they don't understand your logic...

Link to comment
Share on other sites

Your absolutely right. We're here to help but you're confusing everything.

 

Your OP says in summary:

 

The user logs in -> Log in information stored in database -> User goes to account page -> Users adds more information which is added to the database -> You try to add the username they just logged in with to the database with the information they just submitted?

 

That doesn't make sense. You should register a user and they will have perhaps the basic details (Username, Email, Password). They login and are taken to a personalised page where they can enter additional information (E.g. information for their profile). This information is then stored in the database in the same table as their username, email and password using an UPDATE T-SQL statement...

 

I'm not trying to be rude I'm trying to help but no-one can help you if they don't understand your logic...

 

ok i will explain it better, what I'm trying to do really has nothing to do with the login script, only the username they use to login with, or the user_id. so once they are logged in there will be a form for them to add data into about there fish tank (this is an aquarium site) once submitted it goes to the mysql and stores into there, when the person goes to the My Records page it will display all the records that has been added to the database, but the thing i want is with that table, i want it to only show what that user has added to the database not what others users have added

 

is that better? it is hard to explain when you don't know what it is called

Link to comment
Share on other sites

Okay

 

So in your SELECT statement do:

 

SELECT * FROM `fish_tank` WHERE `username` = '{$_SESSION['username']}'

 

Assuming you entered the username when they added details about their fish? If not you just need to add a column to the fish tank table called "username/user_id" and in your SQL statement include the username when you insert the new entry.

 

Some homework for you. Do research on "database relationships" and "foreign keys". Those topics will help you understand how to link things like user accounts to additional information in a relational database.

Link to comment
Share on other sites

Okay

 

So in your SELECT statement do:

 

SELECT * FROM `fish_tank` WHERE `username` = '{$_SESSION['username']}'

 

Assuming you entered the username when they added details about their fish? If not you just need to add a column to the fish tank table called "username/user_id" and in your SQL statement include the username when you insert the new entry.

 

Some homework for you. Do research on "database relationships" and "foreign keys"

 

ok so thats retrieving the sql?

 

so when I'm adding it to the sql, what would i put into the script to add the user_id to the user_id field in the sql?

Link to comment
Share on other sites

Okay you've confused me again.

 

So whats retrieving the SQL

 

I'll assume you mean "data" not "sql"?

 

so when I'm adding it to the sql, what would i put into the script to add the user_id to the user_id field in the sql?

 

I'll assume you ,mean "...user_id field in the table"?

 

I get the feeling you don't know very much SQL (Structured Query Language)? If you wrote the SQL to insert a new record you can add an additional column and value...

 

P.s. Note SQL not T-SQL. I've been doing a lot of work with Microsoft SQL Server lately :S

Link to comment
Share on other sites

Okay you've confused me again.

 

So whats retrieving the SQL

 

I'll assume you mean "data" not "sql"?

 

so when I'm adding it to the sql, what would i put into the script to add the user_id to the user_id field in the sql?

 

I'll assume you ,mean "...user_id field in the table"?

 

I get the feeling you don't know very much SQL (Structured Query Language)? If you wrote the SQL to insert a new record you can add an additional column and value...

 

ok sorry, I'm having trouble wording things because i am new, ill try again, how do i submit the logged in user_id along with the form into the database

Link to comment
Share on other sites

Okay so you don't know how to write an INSERT statement?

 

A generalised example is:

 

INSERT INTO `table` (field1, field2, field3) VALUES ('value1', 'value2', 'value3');

 

But you should research INSERT statements...

Link to comment
Share on other sites

Okay so you don't know how to write an INSERT statement?

 

A generalised example is:

 

INSERT INTO `table` (field1, field2, field3) VALUES ('value1', 'value2', 'value3');

 

But you should research INSERT statements...

 

yes i do know how to insert statements this is mine

 

mysql_select_db("lachlanmcgrath", $con);

$sql="INSERT INTO tracker (Date, Time, Amonia, Nitrite, Nitrate, PH, Salinity, Tempreture)
VALUES
('$_POST[Date]','$_POST[Time]','$_POST[Amonia]','$_POST[Nitrite]','$_POST[Nitrate]','$_POST[PH]','$_POST[salinity]','$_POST[Tempreture]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con);
?>

 

I'm trying to get at, with the insert what would i put into there for it to insert the logged in user_id

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.