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

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2007, 10:37 PM
Oneback Oneback is offline
 
Join Date: Nov 2007
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Problem writing to the database

I am having a bit of a problem writing to the database using a form for a league hosting application I am developing. It is located outside of my forums subfolder (however I don't think that has anything to do with it).

Anyway here is the code:

register.php:

PHP Code:
<?php

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

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''League Registration'); // 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(
    
'League Registration',
);

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

);

// ######################### REQUIRE BACK-END ############################
// ============================================
// Enter the full path to your forum here
// Example: /home/vbadvanced/public_html/forum
// ============================================

$forumpath '/apache/htdocs/forums/';

// ============================================
// No Further Editing Necessary!
// ============================================

if ($forumpath)
{
    if (!
is_dir($forumpath))
    {
        echo 
'Invalid forum path specified! Please edit this file and be sure to include the correct path for your $forumpath variable.';
        exit;
    }

    
chdir($forumpath);
}

require_once(
'./global.php');
require_once(
DIR '/includes/functions_user.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
if (!$vbulletin->userinfo['userid'])
{
    
print_no_permission();

$vbulletin->input->clean_gpc('r''a'TYPE_NOHTML);
$vbulletin->input->clean_gpc('r''u'TYPE_NOHTML);

$navbits = array();
$navbits[$parent] = 'League Registration';

$navbits construct_navbits($navbits);
eval(
'$navbar = "' fetch_template('navbar') . '";');
eval(
'print_output("' fetch_template('League Registration') . '");');


// ############################### start add league ###############################
if ($_POST['do'] == 'addleague')
{
    
//    clean data subbmitted by user    
    
$leaguename =                     $vbulletin->input->clean_gpc('p''leaguename'TYPE_STR);
    
$leaguepassword =                 $vbulletin->input->clean_gpc('p''leaguepassword'TYPE_STR);
    
$leaguepasswordconfirm =         $vbulletin->input->clean_gpc('p''leaguepasswordconfirm'TYPE_STR);
    
$console =                         $vbulletin->input->clean_gpc('p''console'TYPE_STR);
    
$game =                         $vbulletin->input->clean_gpc('p''game'TYPE_STR);
    
$numteams =                     $vbulletin->input->clean_gpc('p''numteams'TYPE_STR);
    
$numgames =                     $vbulletin->input->clean_gpc('p''numgames'TYPE_STR);
    
$adminid =                        $vbulletin->userinfo['userid'];

    
// League Name error checking
    
if (!$leaguename)
        {
            
standard_error('Please enter a league name.');
        }
        else 
            {
            
// Check length
            
$subleague stripslashes($leaguename);
             if(
strlen($subleague) < 6)
                {
                    
standard_error('League name is below 6 characters.');
                 }
            else if(
strlen($subleague) > 30)
                {
                    
standard_error('League name is above 30 characters.');
                 }
            
// Check if league name is not alphanumeric */
             
else if(!eregi("^([0-9a-z])+$"$subleague))
                {
                    
standard_error('League name is not alphanumeric.');
                 }
            }
    
    
// Password error checking
    
if(!$leaguepassword)
        {
            
standard_error('Password not entered.');
          }
        else
            {
             
// Check length
             
$subpass stripslashes($leaguepassword);
             if(
strlen($subpass) < 6)
                {
                    
standard_error('Password is below 6 characters.');
                 }
             
/* Check if password is not alphanumeric */
             
else if(!eregi("^([0-9a-z])+$", ($subpass trim($subpass))))
                {
                    
standard_error('Password is not alphanumeric.');
                 }
             
/* Confirm Password */
            
else if($subpass != $leaguepasswordconfirm
                {
                     
standard_error('Passwords do not match.');
                   }
            }
            
    
// Console error checking
    
if (!in_array($console, array(1234)))
        {
            
standard_error('Invalid console entered.');
        }    
    
    
// Game error checking
    
if (!in_array($game, array(123)))
        {
            
standard_error('Invalid game entered.');
        }
    
    
// Number of teams error checking
    
if (!in_array($numteams, array(1234567)))
        {
            
standard_error('Invalid number of teams entered.');
        }
        
    
// Number of games error checking
    
if (!in_array($numgames, array(12)))
        {
            
standard_error('Invalid number of games entered.');
        }
        
    
// save the data
    
$db->query_write("INSERT INTO " TABLE_PREFIX "leagues (adminid, leaguename, leaguepass, console, game, numteams, numgames) VALUES ($adminid$subleague$subpass$console$game$numteams$numgames)"); 
    
    
// redirect to leagues home
    
header("Location: http://localhost/leagues/index.php");
}
?>
League Register template:

PHP Code:
$stylevar[htmldoctype]
<
html dir="$stylevar[textdirection]lang="$stylevar[languagecode]xmlns="http://www.w3.org/1999/xhtml">
<
head>
<if 
condition="$pages['name'] == 'home'">
    <
meta http-equiv="Cache-Control" content="no-cache" />
    <
meta http-equiv="Pragma" content="no-cache" />
    <
meta http-equiv="Expires" content="0" />
</if>

<
title>$vboptions[hometitle] <if condition="$pagetitle">- $pagetitle</if></title>

$headinclude
</head>
<
body>
$header
$navbar
<br />
    <
table class="tborder" cellpadding="$stylevar[cellpadding]cellspacing="$stylevar[cellspacing]border="0" width="100%" align="center">
    <
tr>
        <
td class="tcat">Errors occured during registration</td>
    </
tr>
    <
tr>
        <
td class="alt1"><ul>$errorlist</ul></td>
    </
tr>
    </
table>
    <
br />

<
br />
<
table align="center" class="page" cellspacing="0" cellpadding="0" width="950">
    <
tr valign="top">
        <
td width="250" style="padding-right: 20px" bgcolor="#333333" align="left">
            <
div>
                <
table border="0" cellpadding="6" cellspacing="1" class="tborder" width="100%">
                    <
thead>
                        <
tr>
                            <
td class="tcat" colspan="0">
                                <
span class="smallfont"><strong>&raquoNavigation</strong></span></td>
                        </
tr>
                    </
thead>
                    <
tr>
                        <
td class="alt1">
                            <
div class="smallfont">&raquo; <a href="#"><strong>Home</strong></a></div>
                            <
div class="smallfont">&nbsp;&gt; <a href="register.php">Register League</a></div>
                            <
div class="smallfont">&nbsp;&gt; <a href="#">Join League</a></div>
                            <
div class="smallfont">&nbsp;&gt; <a href="#">Search League</a></div>
                            <
div class="smallfont">&nbsp;&gt; <a href="#">Support</a></div>
                        </
td>
                    </
tr>
                </
tbody>
                </
table>
            </
div>
            <
div style="padding-top:0px; margin-top:20px;">
                <
table border="0" cellpadding="6" cellspacing="1" class="tborder" width="100%">
                    <
thead>
                        <
tr>
                            <
td class="tcat" colspan="0">
                                <
span class="smallfont"><strong>&raquoAdvertisment</strong></span>
                            </
td>
                        </
tr>
                    </
thead>
                    <
tr>
                        <
td class="alt1" align="center">
                            <
script type="text/javascript"><!--
                                
google_ad_client "pub-1289182137012790";
                                
//200x200, created 12/19/07
                                
google_ad_slot "7532163925";
                                
google_ad_width 200;
                                
google_ad_height 200;
                            
//--></script>
                            
<script type="text/javascript"
                                
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                            </
script>
                        </
td>
                    </
tr>
                </
tbody>
                </
table>
            </
div>
        </
td>
        <
td valign="top" bgcolor="#333333" align="center">
            <
table border="0" cellpadding="6" cellspacing="1" class="tborder" width="100%">
                <
form action="register.php?do=addleague" name="register" method="post">
                     <
input type="hidden" name="s" value="$session[sessionhash]/>
                    <
input type="hidden" name="do" value="addleague" />
                    <
input type="hidden" name="url" value="$url/>
                    <
table class="tborder" cellpadding="$stylevar[cellpadding]cellspacing="$stylevar[cellspacing]border="0" width="100%" align="center">
                        <
tr>
                            <
td class="tcat"><strong>League Registration</strong></td>
                        </
tr>
                        <
tr>
                            <
td class="panelsurround" align="center">
                                <
div class="panel">
                                    <
div style="width:100%" align="left">
                                        <
div class="smallfont" style="margin-bottom: 10px">
                                            <
phrase 1="$vboptions[bbtitle]">Please fill out the form below to create a VirtualSportsDepot.com  LeagueLeague registration is easy and gives you instant access to  build and create your own leagueJust follow the simple steps below to  complete your registration.</phrase>
                                        </
div>
                                        <
div class="smallfont" style="margin-bottom: 10px">
                                            <
strong>League Name </strong>:<br />
                                            <
input type="text" class="bginput" name="leaguename" size="50" maxlength="50" value="$leaguename/>
                                        </
div>
                                    <
fieldset class="fieldset">
                                        <
legend>League Password</legend>
                                            <
table cellpadding="0" cellspacing="$stylevar[formspacer]border="0" width="100%">
                                                <
tr>
                                                    <
td colspan="2">Please enter a password for your leagueNote that passwords are case-sensitive.</td>
                                                </
tr>
                                                <
tr>
                                                    <
td>
                                                        
Password:<br />
                                                        <
input type="password" class="bginput" name="leaguepassword" size="25" maxlength="50" value="$password/>
                                                    </
td>
                                                    <
td>
                                                        
Confirm Password:<br />
                                                        <
input type="password" class="bginput" name="leaguepasswordconfirm" size="25" maxlength="50" value="$passwordconfirm/>
                                                    </
td>
                                                </
tr>
                                            </
table>
                                    </
fieldset>
                                    <
fieldset class="fieldset">
                                        <
legend>League Configuration</legend>
                                            <
table cellpadding="0" cellspacing="$stylevar[formspacer]border="0" width="100%">
                                                <
tr>
                                                    <
td>
                                                          <
label for="console">Console : </label> <br />
                                                          <
SELECT NAME="console" ID="console" SIZE="1">
                                                            <
OPTION value="" SELECTED></OPTION>
                                                            <
OPTION VALUE="1">PS2</OPTION>
                                                            <
OPTION VALUE="2">PS3</OPTION>
                                                            <
OPTION VALUE="3">XBOX</OPTION>
                                                            <
OPTION VALUE="4">XBOX 360</OPTION>
                                                        </
SELECT>
                                                    </
td>
                                                </
tr>
                                                <
tr>
                                                    <
td>
                                                          <
label for="game">Game : </label> <br />
                                                           <
SELECT NAME="game" ID="game" SIZE="1">
                                                            <
OPTION value="" SELECTED></OPTION>
                                                            <
OPTION VALUE="1">All Pro Football</OPTION>
                                                            <
OPTION VALUE="2">Madden Football</OPTION>
                                                            <
OPTION VALUE="3">NCAA Football</OPTION>
                                                        </
SELECT>
                                                    </
td>
                                                </
tr>
                                                <
tr>
                                                    <
td>
                                                          <
label for="teams">Number of Teams : </label> <br />
                                                          <
SELECT NAME="numteams" ID="numteams" SIZE="1">
                                                            <
OPTION value="" SELECTED></OPTION>
                                                            <
OPTION VALUE="1">8</OPTION>
                                                            <
OPTION VALUE="2">10</OPTION>
                                                            <
OPTION VALUE="3">12</OPTION>
                                                            <
OPTION VALUE="4">16</OPTION>
                                                            <
OPTION VALUE="5">20</OPTION>
                                                            <
OPTION VALUE="6">24</OPTION>
                                                            <
OPTION VALUE="7">32</OPTION>
                                                        </
SELECT>
                                                    </
td>
                                                </
tr>
                                                <
tr>
                                                    <
td>
                                                          <
label for="games">Number of Games: </label> <br />
                                                          <
SELECT NAME="numgames" ID="numgames" SIZE="1">
                                                            <
OPTION value="" SELECTED></OPTION>
                                                            <
OPTION VALUE="1">12</OPTION>
                                                            <
OPTION VALUE="2">16</OPTION>
                                                        </
SELECT>
                                                    </
td>
                                                </
tr>
                                            </
table>
                                    </
fieldset>
                                </
div>
                                <
div style="margin-top: 10px">
                                    <
input type="submit" class="button" value="Submit" />
                                </
div>
                            </
td>
                        </
tr>
                    </
table>
                </
form>
            </
table>
        </
td>
    </
tr>
</
table>
<
br />
$footer
</body>
</
html
If anyone could help out it would be greatly appreciated.

Thanks,

Oneback
Reply With Quote
  #2  
Old 12-23-2007, 08:57 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would help if you told us what the problem was...

(P.S. use [php] and [/php] tags around your PHP code. )
Reply With Quote
  #3  
Old 12-23-2007, 11:38 AM
Oneback Oneback is offline
 
Join Date: Nov 2007
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well basically after messing around with it a little bit more when pressing submit all it does is redirects me to register.php?do=addleague without running any code. I know it's something simple that I am probably over looking.

At first I I thought maybe it wasn't picking up the data from the $_POST but now I believe it's not even running the code within if ($_POST['do'] == 'addleague').
Reply With Quote
  #4  
Old 12-23-2007, 12:51 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Underneath where you check if the form was submitted (if($_POST['do...) add this:
PHP Code:
echo 'Processing Begins';
var_dump($_POST);
die(); 
Run the script once and post the output here.
Reply With Quote
  #5  
Old 12-23-2007, 01:12 PM
Oneback Oneback is offline
 
Join Date: Nov 2007
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am not 100% sure I put it in the right location as I am fairly new at this but here is what I did:

PHP Code:
// ########## start add league ##########
if ($_POST['do'] == 'addleague')
{
    echo 
'Processing Begins';
    
var_dump($_POST);
    die();

All it did was bring me back to the same page, but instead of having http://localhost/leagues/register.php in the url it had http://localhost/leagues/register.php?do=addleague

Again thank you for any help you can provide.
Reply With Quote
  #6  
Old 12-23-2007, 02:12 PM
Dead Eddie's Avatar
Dead Eddie Dead Eddie is offline
 
Join Date: Apr 2004
Location: at Home...
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If it's in the URL, it's in the GET superglobal, not the POST.
Reply With Quote
  #7  
Old 12-23-2007, 02:59 PM
Oneback Oneback is offline
 
Join Date: Nov 2007
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dead Eddie View Post
If it's in the URL, it's in the GET superglobal, not the POST.
Excuse my ignorance but how exactly would I go about fixing that?

Thank you for your help.
Reply With Quote
  #8  
Old 12-23-2007, 03:15 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You use $POST_ when you are grabbing information from a form (person fills out a form - say a name - and you want to use that information on the next page) and you use $GET_ when you are you are getting the variable from the url (url/page.php$do=variable). So, try using $GET_['do'] or $REQUEST_['do'].

(I think I got that right, I do need more coffee this morning!)
Reply With Quote
  #9  
Old 12-23-2007, 03:29 PM
Oneback Oneback is offline
 
Join Date: Nov 2007
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
You use $POST_ when you are grabbing information from a form (person fills out a form - say a name - and you want to use that information on the next page) and you use $GET_ when you are you are getting the variable from the url (url/page.php$do=variable). So, try using $GET_['do'] or $REQUEST_['do'].

(I think I got that right, I do need more coffee this morning!)
Well I tried that and I still have the same problem.

Here is what I've got:

League Register template:

PHP Code:
<form action="register.php?do=addleague" method="post">
<
input type="hidden" name="do" value="addleague" />
// League Registration Form
</form
register.php:

PHP Code:
if ($_GET['do'] == 'addleague')
{
    echo 
'Processing Begins';
    
var_dump($_POST);
    die();

Reply With Quote
  #10  
Old 12-23-2007, 10:03 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

remove the "do=addleague" from the action="..." in your form.

In register.php change $_GET['do'] to $_REQUEST['do'].

Run the code, you should be getting some output because your only send data from one page to another.
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 09:54 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.04733 seconds
  • Memory Usage 2,484KB
  • 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
  • (6)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete