PDA

View Full Version : Get user session and insert


Stewartiee
12-08-2009, 11:57 PM
Hey,
What i'm trying to do is get the session username, which is easy, but i'm finding it difficult to insert it into mysql.

The scenario is users who have permission can access an admin panel to add posts etc. I was their session username to be submitted along with posts so in the mysql table, their name will be beside their posts. I have tried a few codes with the latest being below. This might be really simple, and I have just overlooked something.

Any help is appreciated.

$_POST['username'] = $_SESSION['username'];
$author=$_POST['username'];

epheterson
12-09-2009, 05:04 AM
I don't understand why you're introducing $_POST into this deal. Is the addition done on a new page and it's submitted through a form via POST?

If this is the case, $_SESSION has nothing to do with it.

What you have to do is bring the username into a local variable, $author as you're doing, and insert that exactly as you're inserting everything else into the database (I assume everything else is a variable as well).

Please give some clarification on exactly where we're having problems. Also, do some echos to see what strings are in what variables to be sure you're passing the correct information around.

Good luck!

bucket
12-09-2009, 03:38 PM
So you want a basic register system? With a dropdown value as 1, 2, and 3.

The ranks would be a value as like, 1 is regular user, 2 is moderator, and 3 is administrator.

The pages would be made as what rank the user is and if he/she is the correct or high enough permissions to access that page?

Is that correct? Am I on the right track?

Old Pedant
12-09-2009, 07:55 PM
I don't believe you *can* assign *TO* a $_POST value, in any case.

The $_POST collection is (or should be!) read-only.

djm0219
12-09-2009, 08:40 PM
I don't believe you *can* assign *TO* a $_POST value, in any case.

The $_POST collection is (or should be!) read-only.

It's considered read-only but you can in fact set a $_POST value for use in the code being executed. It won't survive across pages though of course.

Old Pedant
12-09-2009, 10:08 PM
Fascinating. ASP and ASP.NET and I *think* JSP treat post data as read only.