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 04-21-2012, 01:26 PM
Preech Preech is offline
 
Join Date: Aug 2002
Location: Fort Campbell
Posts: 325
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Forms and Insert to the DB

So I am still working on my mod, where the admin can create, lets say a new artist.
I can get the page to show up, everything looks good, when I go to submit the form, nothing happens.

Here is the Php Code
PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''vbmusic_create_artist');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('vbmusic_create_artist',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => 'Create Artist'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'Create Artist';

if (
$_POST['do'] == 'createartist')
{
if (
$createartist=='send') {

        
$name $vbulletin->input->clean_gpc('p''name'TYPE_STR);
    
$dbirth $vbulletin->input->clean_gpc('p''dbirth'TYPE_UINT);
    
$country $vbulletin->input->clean_gpc('p''country'TYPE_STR);
    
$homepage $vbulletin->input->clean_gpc('p''homepage'TYPE_STR);
    
    if (
$name!='') {
    
    
$vbulletin->db->query_write("INSERT INTO " TABLE_PREFIX "artist
        (arname, dbirth, lbirth, homepage)
        VALUES ('"
.$name."','".$dbirth."', '".$country."') ");    
        
    
$id $vbulletin->db->insert_id();
    
    
$vbulletin->db->query_write("INSERT INTO " TABLE_PREFIX "artdescr
        (arid, ardescr)
        VALUES (
            '"
.$vbulletin->db->escape_string($id)."',
            '"
.$vbulletin->db->escape_string('')."' 
        "
);
    
    
    
    
//$vbulletin->url = "forms.php?do=editform&fid=$id";    
    
eval(print_standard_redirect('redirect_insertform'));



      
//if ($save) $mess="Your data was successfully saved.";
     // else $mess="There was an SQL error!";
      
}
   
//else $mess="Please provide a name!";

}
}
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('vbmusic_create_artist');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('dbirth'$dbirth);
$templater->register('pagetitle'$pagetitle);
print_output($templater->render());

?>
Here is the template
PHP 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}


<
br />
    
<
div class="colmask leftmenu">
    <
div class="colleft">
        <
div class="col1">
            <!-- 
Column 1 start -->



<
div class="audio_head">Create Artist</div>
<
div class="audio_body">


    
<!--<
form action="./vbmusic_create_artist.php" method="post">-->
<
form class="vbform block" action="vbmusic_create_artist.php?do=createartist" method="post" name="vbform" onsubmit="return .prepare_submit(0, 0)">
<
input type="hidden" name="do" value="insertform" />
<
input type="hidden" name="s" value="{vb:raw session.sessionhash}" />
<
input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />

<
table align="center" cellspacing="0" cellpadding="0" width="100%" class="tablec"
 <
tr
  <
td valign="top" align="center">
   <
table align="center" cellspacing="10" cellpadding="0" width="100%">
<
input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
    <
tr>
     <
td style="width:35%;" align="right">Name :</td>
     <
td style="width:65%;" align="left">
 <
input type="text" name="name" size="50" value="">
   
     </
td>
    </
tr>
    <
tr>
     <
td align="right" class="data1">Date of birth :</td>
     <
td align="left">
      <
input type="text" name="{vb:raw dbirth}" size="50" value="">
     </
td>
    </
tr>
    <
tr>
     <
td align="right" >Land of birth :</td>
     <
td align="left">{vb:raw lbirth}</td>
    </
tr>
    <
tr>
     <
td align="right" >Homepage :</td>
     <
td align="left">
      <
input type="text" name="{vb:raw homepage}" size="50" value="">
     </
td>
    </
tr>
   </
table>
  </
td>
 </
tr>
</
table>
<
table align="center" cellspacing="0" cellpadding="0" width="100%" 
 <
tr
  <
td valign="top" align="center">
   <
table align="center" cellspacing="10" cellpadding="0" width="100%">
    <
tr>
     <
td style="width:35%;" align="right" class="data1">Upload image from URL :</td>
     <
td style="width:65%;" align="left">
      <
input type="hidden" name="MAX_FILE_SIZE" value="".($csiz*1024)."\" />
      <input class="
text" type="text" name="covurl" size="55" >
     </td>
    </tr>
    <tr>
     <td align="
right">Upload image from your PC :</td>
     <td align="
left">
      <input type="
hidden" name="MAX_FILE_SIZE" value="".($csiz*1024)."" />
      <input type="
file" name="covfil" size="50" accept="image/jpeg">
     </td>
    </tr>
   </table>
  </td>
 </tr>
</table>
<table align="
center" cellspacing="20" cellpadding="0" width="100%" class="tablec"> 
 <tr> 
  <td valign="
middle" align="center"><input class="button" type="submit" value="Submit!"></td>
 </tr>
</table>
</form>

    </div>


            <!-- Column 1 end -->
        </div>
        <div class="
col2">
            <!-- Column 2 start -->
<div class="
audio_head">Menu</div>
<div class="
audio_body">
        <table align="
center" cellspacing="0" cellpadding="0" width="100%" > 
 <tr> 
  <td valign="
top" align="center">
   <table align="
center" cellspacing="5" cellpadding="0" width="100%"> 
    <tr> 
     <td align="
left"><a href="vbmusic.php" title="" alt="">- Music Home</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"browse.php?typ=artist\" title=\"\" alt=\"\">- Browse Artist</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"browse.php?typ=album\" title=\"\" alt=\"\">- Browse Albums</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"browse.php?typ=genre\" title=\"\" alt=\"\">- Browse Genre</a></td>
    </tr>

 <tr> 
     <td align=\"left\"><a href=\"import.php\" title=\"\" alt=\"\">- Import Albums</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"config.php\" title=\"\" alt=\"\">- Config Settings</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"usr_list.php\" title=\"\" alt=\"\">- Userlist</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"showlog.php\" title=\"\" alt=\"\">- Show Log</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"stats.php\" title=\"\" alt=\"\">- Statistics</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"create_artist.php\" title=\"\" alt=\"\">- Create artist</a></td>
    </tr>
    <tr> 
     <td align=\"left\"><a href=\"del_artist.php\" title=\"\" alt=\"\">- Delete artist</a></td>
    </tr>


</table>
  </td>
 </tr>
</table>
        </div>
    

            
            <!-- Column 2 end -->
        </div>
    </div>
</div>
    {vb:raw footer}
  </body>
</html> 
Also, I would I go about getting the select a option info from the database.
Reply With Quote
  #2  
Old 04-21-2012, 01:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have this in your form tag:

Code:
onsubmit="return .prepare_submit(0, 0)

where is the function .prepare_submit()? Is that a type? I'm not a js expert but I don't know if you can have a '.' there.
Reply With Quote
  #3  
Old 04-21-2012, 02:03 PM
Preech Preech is offline
 
Join Date: Aug 2002
Location: Fort Campbell
Posts: 325
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didnt realize it was there. With it gone still not working.
Reply With Quote
  #4  
Old 04-21-2012, 02:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK - you have this in your php file:

Code:
if ($_POST['do'] == 'createartist')

but your form data has do set to "insertform". I think you want to check $_GET['do'], or else change the hidden field value (and probably take the ?do=createartist off the form action or else your code will be confusing).
Reply With Quote
  #5  
Old 04-23-2012, 10:11 AM
Preech Preech is offline
 
Join Date: Aug 2002
Location: Fort Campbell
Posts: 325
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''vbmusic_create_artist');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('vbmusic_create_artist',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => 'Create Artist'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'Create Artist';

$artist "artist";
$name =  $_POST['name'];
$dbirth =  $_POST['dbirth'];
$country =  $_POST['country'];
$homepage =  $_POST['homepage'];

if (
$_REQUEST['do'] == "createartist")
{
$createartist $vbulletin->input->clean_array_gpc('p', array(
                
'name' => TYPE_STR,
                
'dbirth' => TYPE_INT,
                
'country' => TYPE_STR,
                
'homepage' => TYPE_NOHTML
      
));

if (
$name!='') {
    
    
$vbulletin->db->query_write("INSERT INTO " TABLE_PREFIX "" $artist "
        (arname, dbirth, lbirth, homepage)
VALUES     (" 
$db->escape_string($vbulletin->GPC['name']) . "," $db->escape_string($vbulletin->GPC['dbirth']) . "," $db->escape_string($vbulletin->GPC['country']) . "," $db->escape_string($vbulletin->GPC['homepage']) . ")
"
);      
    
$id $vbulletin->db->insert_id();
    
    
$vbulletin->db->query_write("INSERT INTO " TABLE_PREFIX "artdescr
        (arid, ardescr)
        VALUES ("
.$db->escape_string($vbulletin->GPC['id']).",".$db->escape_string($vbulletin[''])." ");

      }
   

}


// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('vbmusic_create_artist');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('name'$name);
$templater->register('dbirth'$dbirth);
$templater->register('artist'$artist);
$templater->register('pagetitle'$pagetitle);
print_output($templater->render());

?>
PHP Code:
<div class="audio_head"><h2>Create Artist</h2></div>
<
div class="audio_body formcontrols">
<
br />
<
form action="vbmusic_create_artist.php?do=createartist" method="post" class="vbform block">

<
div class="blockrow">
    <
label for="name">{vb:rawphrase artist_name}:</label>
    <
div>
<
input type="text" class="primary textbox" name="name" id="name" value="{vb:raw name}" size="50" maxlength="85" tabindex="1" />
        
    </
div>
</
div>
<
div class="blockrow">
    <
label for="birthday">{vb:rawphrase artist_birthday}:</label>
    <
div>
        <
input name="birth" type="text" id="dbirth" class="textbox" size="40" maxlength="100" />
    </
div>
</
div>
<
div class="blockrow">
    <
label for="country">{vb:rawphrase artist_country}:</label>
    <
div>
        <
input name="country" type="text" id="country" class="textbox" size="40" maxlength="100" />
    </
div>
</
div>
<
div class="blockrow">
    <
label for="homepage">{vb:rawphrase artist_homepage}:</label>
    <
div>
        <
input name="homepage" type="text" id="homepage" class="textbox" size="40" maxlength="100" />
    </
div>
</
div>
<
div class="blockrow">
    <
label for="upload_url">{vb:rawphrase artist_upload_url}:</label>
    <
div>
        <
input name="name" type="text" id="name" class="textbox" size="40" maxlength="100" />
    </
div>
</
div>
<
div class="blockrow">
    <
label for="upload_pc">{vb:rawphrase artist_upload_pc}:</label>
    <
div>
<
input name="covfil" size="35" tabindex="1" type="file" />
<
input name="MAX_FILE_SIZE" value="999999999" type="hidden" />
    </
div>
</
div>
<
br /><br /><br /><br />
<
div class="blockfoot actionbuttons">
    <
div class="group">
        <
input class="button" name="add" type="submit" id="submit0" value="{vb:rawphrase submit}" />
        <
input class="button" name="cancel" type="button" id="cancel" value="{vb:rawphrase cancel}" onclick="window.location.href='vbmusic.php?'" type="button" />
    </
div></div>


<
input type="hidden" name="s" value="{vb:raw session.sessionhash}" />
<
input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<
input type="hidden" name="do" value="createartist" />
</
form>

</
div></div
Can anyone tell me what I'm doing wrong. I can't get the info to insert into the database.
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 03: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.03947 seconds
  • Memory Usage 2,355KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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