Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2011, 05:15 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How Can I insert the username of who submitted a form to the database?

Hello everyone, I am trying to capture the username of whoever submits a custom form I created. I need to insert that username of who submits the form into a database table I created. I need this to first have a record of who submitted the form and also to later print out the username next to the form submitted, as well as restrict later access to that form using if conditions, but first I need to get that username. Any one has any ideas how to go about this or point me in the right direction?? Please any information would be very useful. Thank you for your time everyone.
Reply With Quote
  #2  
Old 07-13-2011, 05:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think the username should be available in $vbulletin->userinfo['username'].
Reply With Quote
  #3  
Old 07-13-2011, 05:27 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Right but how does the form know that? Should I just insert that while I'm inserting the form values? I don't get how that knows that that form was submitted by that user. Anyone can explain please??

This is my form:
HTML Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
   {vb:raw headinclude}
   {vb:raw headinclude_bottom}
</head>
<body>
    
    {vb:raw header}
    
    {vb:raw navbar}

    
<div id="pagetitle">
   <h1>{vb:raw pagetitle}</h1>
</div>

<div id="usercp_content">

{vb:raw oftw_sidemenu}

<div class="cp_content" style="width: 80%; float: right;">
<h2 class="blockhead">Contests Of The Week</h2>
<div class="blocksubhead">
<center><form action="nominate.php" method="post">
Enter Image URL to Nominate: <input type="text" name="imgurl"><input type="submit" name="submit">
</form>
</center>
</div>
        {vb:raw print_nominations}
</div>


</div>				
    {vb:raw footer}

  </body>
</html>
This processes the form:
PHP Code:
<?php 

require_once('./global.php');

define('CSRF_PROTECTION'true);


if (!isset(
$_POST['submit'])) { 



else { 

    
$imgurl = empty($_POST['imgurl']) ? die ("ERROR: Enter a imgurl") : mysql_escape_string($_POST['imgurl']);
     
    
// create query 
    
$db->query_write("INSERT INTO oftw_nominations (imgurl) VALUES ('$imgurl')");
    
    
header"refresh:0; url=http://development.aniworlds.net/oftw_nominations.php" );
    
// close connection 
    
mysql_close($connection); 


?>
Any ideas how I can also insert the username of whoever submitted this form?
Reply With Quote
  #4  
Old 07-13-2011, 05:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

When you include global.php, it does a lot of stuff for you like makes sure the user is logged in (actually you have to check that - if the user id is '0' then the user is an unregistered guest). So hopefully the answer to your question is that it should all be handled by including global.php.

(If this doesn't answer your question I'll let someone else try )
Reply With Quote
  #5  
Old 07-13-2011, 05:36 PM
Disasterpiece's Avatar
Disasterpiece Disasterpiece is offline
 
Join Date: Apr 2007
Location: GER
Posts: 765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php 

require_once('./global.php');

define('CSRF_PROTECTION'true);


if (!isset(
$_POST['submit'])) { 



else { 

    
$imgurl = empty($_POST['imgurl']) ? die ("ERROR: Enter a imgurl") : mysql_escape_string($_POST['imgurl']);
     
    
// create query 
    
$db->query_write("INSERT INTO oftw_nominations (imgurl, username) VALUES ('$imgurl', '".$vbulletin->userinfo['username']."')");
    
    
header"refresh:0; url=http://development.aniworlds.net/oftw_nominations.php" );
    
// close connection 
    
mysql_close($connection); 


?>
should do the trick
Reply With Quote
  #6  
Old 07-13-2011, 05:42 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

P E R F E C T !! I knew it had to be something simple Thank you SOO much Disasterpiece, hopefully you'll be seeing my first mod up here soon enough? Thanks to everyone's help, it's really easy to learn anything when you have this level of support. Thanks guys.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06453 seconds
  • Memory Usage 2,223KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete