vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How Can I insert the username of who submitted a form to the database? (https://vborg.vbsupport.ru/showthread.php?t=266746)

EquinoxWorld 07-13-2011 05:15 PM

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. :)

kh99 07-13-2011 05:24 PM

I think the username should be available in $vbulletin->userinfo['username'].

EquinoxWorld 07-13-2011 05:27 PM

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?

kh99 07-13-2011 05:34 PM

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 :) )

Disasterpiece 07-13-2011 05:36 PM

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

EquinoxWorld 07-13-2011 05:42 PM

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. :)


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

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02792 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete