vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Problem writing to the database (https://vborg.vbsupport.ru/showthread.php?t=165906)

Oneback 12-22-2007 10:37 PM

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

Opserty 12-23-2007 08:57 AM

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

(P.S. use [php] and [/php] tags around your PHP code. )

Oneback 12-23-2007 11:38 AM

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

Opserty 12-23-2007 12:51 PM

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.

Oneback 12-23-2007 01:12 PM

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.

Dead Eddie 12-23-2007 02:12 PM

If it's in the URL, it's in the GET superglobal, not the POST.

Oneback 12-23-2007 02:59 PM

Quote:

Originally Posted by Dead Eddie (Post 1407586)
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.

Lynne 12-23-2007 03:15 PM

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

Oneback 12-23-2007 03:29 PM

Quote:

Originally Posted by Lynne (Post 1407633)
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();



Opserty 12-23-2007 10:03 PM

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.


All times are GMT. The time now is 06:25 AM.

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.01586 seconds
  • Memory Usage 2,014KB
  • 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
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete