Jump to content

[SOLVED] Inserting "current User" into record when form is submitted.


Recommended Posts

I'm building my first webpage with PHP and have finally ran into an issue I can't find a solution for. When submitting a form from a user, I want to also submit the currently logged in userid into the record. A session is created when the user logs in Can someone shed some light on this? Attached is the code I think you need to see. Let me know if you need more.

 

 

[attachment deleted by admin]

haven't looked at the code, but you shouldn't have to submit the current user, as the page you submit to can just start the session up and see who is logged in. putting it in a hidden input is actually a HORRIBLE idea, as anyone can just change that value before submitting and change data for a different user

I have a form that the user submits to create a record. I need to have a field that stores which username created the record. It would need to be something where when the form is submitted, the logged in user name gets stored with the other info in the record.

A session is created when the user logs in.

 

i assume you put the username (or at least the user id) in the session when they login? retrieve that info when processing the data. make a column in your table for keeping the username (or user id) and add that value to your insert statement

I do have the user name being stored in the session. I'm just not sure exactly how to get it from the session data (syntax).  I have this in storing the form data. Do I need to set a session variable or is this the right (or wrong) idea?

@$pfw_strQuery = "INSERT INTO `rrequest`(`vmake`,`vmodel`,`vin`,`mileage`,`probdescrip`,`userid`)VALUES

 

(\"$Vmake\",\"$vmodel\",\"$vin\",\"$mileage\",\"$probdescrip\",\SESSIONS())" ;

What key is the username stored in? aka, how did you store the username in the session? if you used 'userid', it would be like so:

<?php
session_start(); //this goes at the top of the script

$userid = mysql_real_escape_string($_SESSION['userid']);
@$pfw_strQuery = "INSERT INTO `rrequest`(`vmake`,`vmodel`,`vin`,`mileage`,`probdescrip`,`userid`) VALUES ('$Vmake','$vmodel','$vin','$mileage','$probdescrip','$userid')";
?>

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.