lmcgr44 Posted April 22, 2012 Share Posted April 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/ Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339483 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339484 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339486 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339487 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339490 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339492 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339515 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339517 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339521 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339524 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339525 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339526 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339530 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339534 Share on other sites More sharing options...
cpd Posted April 22, 2012 Share Posted April 22, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339535 Share on other sites More sharing options...
lmcgr44 Posted April 22, 2012 Author Share Posted April 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261398-adding-data-to-mysql/#findComment-1339539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.