coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: tim18 on September 02, 2007, 06:31:42 AM

Title: Inserting username into a form
Post by: tim18 on September 02, 2007, 06:31:42 AM
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
Title: Re: Inserting username into a form
Post by: Sami on September 02, 2007, 09:39:31 AM
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
Title: Re: Inserting username into a form
Post by: tim18 on September 02, 2007, 03:09:17 PM
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...
Title: Re: Inserting username into a form
Post by: Sami on September 02, 2007, 03:29:14 PM
try this

$user_name = get_username(USER_ID);


Or this

$user_name = USER_NAME;
Title: Re: Inserting username into a form
Post by: tim18 on September 02, 2007, 03:54:11 PM
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
Title: Re: Inserting username into a form
Post by: Sami on September 02, 2007, 04:14:03 PM
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