whoopass Posted April 9, 2008 Share Posted April 9, 2008 OKay, I'll try to explain this as best I can. I have a login system. When a user registers and then logs in, he/she is shown a web page. On this web page I have a form where I want the user to enter data. What function or command would I use to ensure that the data entered coincides with the active user? i.e. I want my table to reflect the username and the data entered. Such as username, data1, data2, data3. I am able to insert the data but I don't know how to enter the active users username with the data. Hope this makes sense. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
unsider Posted April 9, 2008 Share Posted April 9, 2008 Sounds like you want to take a look at $_SESSION values. Go read up a quick tutorial or two and see if that's the solution to your problem. Quote Link to comment Share on other sites More sharing options...
whoopass Posted April 9, 2008 Author Share Posted April 9, 2008 Yes i do want to insert session values. The value being the username of the active user and also insert the data he enters on the form. So when the submit button is pressed, I want the username of the active user and the data on the same table. Not sure how to insert the user with the data. Quote Link to comment Share on other sites More sharing options...
unsider Posted April 9, 2008 Share Posted April 9, 2008 Quick little script, to generalize the idea. <?php // do some kind of test to see if user is logged in if($session->logged_in){ // test if the $_POST values have been set on the form if(isset($_POST['textarea'])) { // set your variables $text = $_POST['text']; $username = $_SESSION['username']; // if not set, make sure they know if(!isset($_POST['textarea'])) { echo "Fill in the form please."; } // SQL query to insert the data $sql="INSERT INTO 'table' VALUES (' ', '$text', '$username')"; // if cant connect, present error, or die(); if (!@mysql_query($sql)) { echo 'Error adding query: ' . mysql_error(); } } } ?> Look that over, and see if it helps your situation. Quote Link to comment Share on other sites More sharing options...
whoopass Posted April 9, 2008 Author Share Posted April 9, 2008 Okay I was able to pass the active user to the table. Thank you. Do you know why I cannot overwrite the data using the INSERT function when entering new data? The old data won't change. If the user wants to change the data it doesn't work. If I use UPDATE, only one row is created. No new rows are made. Example. Marty logs in, enters his data. The database is updated. Billy logs in, enters his data. Only Billy's data is there. Marty's data is overwritten with Billy's. Using UPDATE 'table' SET variable = '$variable', etc etc. Thanks again. Quote Link to comment Share on other sites More sharing options...
whoopass Posted April 9, 2008 Author Share Posted April 9, 2008 Okay, I think I have it now. I was using two different tables. Instead, I merged my data table into my users table and by doing this I was able to update the users data using the UPDATE statement and WHERE username = $username. Because the users must register first thereby setting their information before the data needed to be entered. Thanks. Quote Link to comment 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.