Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Inserting username into a form  (Read 2761 times)

0 Members and 1 Guest are viewing this topic.

tim18

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 22
Inserting username into a form
« 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
« Last Edit: September 02, 2007, 04:09:07 pm by Sami »
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Inserting username into a form
« Reply #1 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
Logged
‍I don't answer to PM with support question
Please post your issue to related board

tim18

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 22
Re: Inserting username into a form
« Reply #2 on: September 02, 2007, 03:09:17 pm »

Thanks Sami

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

Code: [Select]
$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...
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Inserting username into a form
« Reply #3 on: September 02, 2007, 03:29:14 pm »

try this
Code: [Select]
$user_name = get_username(USER_ID);

Or this
Code: [Select]
$user_name = USER_NAME;
Logged
‍I don't answer to PM with support question
Please post your issue to related board

tim18

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 22
Re: Inserting username into a form
« Reply #4 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
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Inserting username into a form
« Reply #5 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
Logged
‍I don't answer to PM with support question
Please post your issue to related board
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 21 queries.