Oneback
12-22-2007, 10:37 PM
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
// ####################### 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(1, 2, 3, 4)))
{
standard_error('Invalid console entered.');
}
// Game error checking
if (!in_array($game, array(1, 2, 3)))
{
standard_error('Invalid game entered.');
}
// Number of teams error checking
if (!in_array($numteams, array(1, 2, 3, 4, 5, 6, 7)))
{
standard_error('Invalid number of teams entered.');
}
// Number of games error checking
if (!in_array($numgames, array(1, 2)))
{
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:
$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>» Navigation</strong></span></td>
</tr>
</thead>
<tr>
<td class="alt1">
<div class="smallfont">» <a href="#"><strong>Home</strong></a></div>
<div class="smallfont"> > <a href="register.php">Register League</a></div>
<div class="smallfont"> > <a href="#">Join League</a></div>
<div class="smallfont"> > <a href="#">Search League</a></div>
<div class="smallfont"> > <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>» Advertisment</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 League. League registration is easy and gives you instant access to build and create your own league. Just 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 league. Note 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
Anyway here is the code:
register.php:
<?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(1, 2, 3, 4)))
{
standard_error('Invalid console entered.');
}
// Game error checking
if (!in_array($game, array(1, 2, 3)))
{
standard_error('Invalid game entered.');
}
// Number of teams error checking
if (!in_array($numteams, array(1, 2, 3, 4, 5, 6, 7)))
{
standard_error('Invalid number of teams entered.');
}
// Number of games error checking
if (!in_array($numgames, array(1, 2)))
{
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:
$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>» Navigation</strong></span></td>
</tr>
</thead>
<tr>
<td class="alt1">
<div class="smallfont">» <a href="#"><strong>Home</strong></a></div>
<div class="smallfont"> > <a href="register.php">Register League</a></div>
<div class="smallfont"> > <a href="#">Join League</a></div>
<div class="smallfont"> > <a href="#">Search League</a></div>
<div class="smallfont"> > <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>» Advertisment</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 League. League registration is easy and gives you instant access to build and create your own league. Just 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 league. Note 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