Using addForm.php - insert logged in user num

7 posts by 2 authors in: Forums > CMS Builder
Last Post: January 2, 2012   (RSS)

By gversion - December 31, 2011

Hello,

I'm trying to setup the form, addForm.php and would like to auto-insert the I'd number of the currently logged in user so the new listing is associated with the logged in user and not the default" 0".

I have changed the code to be as follows, but it's not working:

createdDate      = NOW(),
                      updatedDate      = NOW(),
                      createdByUserNum = '".mysql_escape($CURRENT_USER['num'])."',
                      updatedByUserNum = '0'")


Could someone please help me out?

Thank you,
Greg

Re: [gversion] Using addForm.php - insert logged in user num

By Jason - December 31, 2011

Hi Greg,

You should also assign updatedByUserNum to be the num of the currently logged in user like this:

createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '".mysql_escape($CURRENT_USER['num'])."',
updatedByUserNum = '".mysql_escape($CURRENT_USER['num'])."'")


Hope this helps. If you are still experiencing trouble, please let us know the exact nature of the problem and we can look into it further.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Using addForm.php - insert logged in user num

By gversion - December 31, 2011

Hi Jason,

Thanks for help. I have updated the code as you suggested but when I view the listing in the cmsAdmin area it still says:


Created Dec 31st, 2011 - 06:02:52 PM (by Unknown) change
Last Updated Dec 31st, 2011 - 06:02:52 PM (by Unknown)


How can I make it display the username of the person that created the listing, rather than "unknown"?

Thanks again,
Greg

Re: [gversion] Using addForm.php - insert logged in user num

By Jason - December 31, 2011

Hi Greg,

That comes up when the value of createdByUserNum or updatedByUserNum is not a valid user number.

One potential cause is that the person is not logged in when the record is created.

Does your form force a person to be logged in before they can create a record?

If this doesn't fix it, please attach the .php file you're working with so I can take a closer look at your code.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [gversion] Using addForm.php - insert logged in user num

By Jason - January 2, 2012

Hi Greg,

I think I may see the problem.

At the very top of your page, you have a require_once() statement to require cmsAdmin/lib/init.php.

Then, down below your code that populates the database you require the viewer_functions.php library. This may be affecting the value of $CURRENT_USER. Try this change, remove this line:

require_once "cmsAdmin/lib/init.php";

and replace it with this:
require_once "cmsAdmin/lib/viewer_functions.php";

if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }


This way you are assuring that $CURRENT_USER has a value before anything is entered into the database.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Using addForm.php - insert logged in user num

By gversion - January 2, 2012

Hi Jason,

That's worked! :) Thanks for taking the time to help me with that one.

Regards,
Greg