Inserting username into a form Inserting username into a form
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Inserting username into a form

Started by tim18, September 02, 2007, 06:31:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tim18

Hello all,

I've made a relatively simple form that submits the values of several text boxes into a new table on my database.
One of those is a 'name' field. However I don't want the user to be able to write their own name, but rather get the users user name and insert that value instead.

I tried just changing the variable to the constant "{USER_NAME}" but it didn't like that at all.

I'm sure this is not that complicated... or is it?

Thanks
Tim

Sami

USER_NAME is constant and so it's global if you included init.inc.php to your page , maybe you are put it wrong way
post your code if you need more support
‍I don't answer to PM with support question
Please post your issue to related board

tim18

Thanks Sami

Well ok, here is the php that passes the variables onto the database.

$user_name = get_username($uid);
$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$user_name', '$email', '$datetime')";


include/init.inc.php is defined at the start.

Its actually returning "anonymous" now so i think i'm on the right track...

Sami

try this

$user_name = get_username(USER_ID);


Or this

$user_name = USER_NAME;
‍I don't answer to PM with support question
Please post your issue to related board

tim18

Sami

You are a genius. Thanks for taking the time to think about that  ;)

You've made one Australian teenager very happy :)

Both options work seamlessly.

Thank-you

Tim

Sami

You are welcome ,

Actually using 2nd method would save more resource than first one and it's recommended
To get any other user's name than current user you can use get_username function
‍I don't answer to PM with support question
Please post your issue to related board