Unless I misunderstood, Logicians Web templates are for reading from the DB, not wrting to.
Now I'm a newbie php coder, and code from example alot; so I'm mostly familiar with the code examples I've been.
I have a custom page, the custom page uses a custom template. Now all I need is to access the Vbulletin databse query functions. However I'm unsure how certain things differ.
For instance:
Code:
// Validate the email address.
if (!empty($_POST['email'])) {
$rn = escape_data($_POST['race_name']);
} else {
echo '<p><font color="red" size="+1">Please enter a Race Name address!</font></p>';
$rn = FALSE;
}
I think would now be
Code:
// Validate the email address.
if (!empty($_POST['race_name'])) {
$rn = escape_string($_POST['race_name']);
} else {
echo '<p><font color="red" size="+1">Please enter a Race Name</font></p>';
$rn = FALSE;
}
Ok I'm not certain but I think that would be correct for making sure the user entered info.
Now reading and writing to the Db confuses me abit more.
Code:
if ($rn) { // If everything's OK.
// Make sure the email address is available.
$query = "SELECT race_name FROM races WHERE race_name='$rn'";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
if (mysql_num_rows($result) == 0) { // Available.
This checks to make sure the race_name is available.
But how does vbulletin handle mysql_num_rows?
And how about writing to the database?
Code:
$query = "INSERT INTO races (race_name) VALUES ('$rn', NOW() )";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
Again I'm pretty new to PHP and can code and adapt by example, but i'm abit stumped as to vbulletins mysql handling syntax.
-Sokol
Here is the NON vbulletin php file that I began to make.
Quote:
<?php
// This page allows users to add URL's to the database.
require_once('includes/mysql_connect.php'); //connect to the database [NOTE: change to default dir "../includes/mysql_connect" for production site.
if(isset($_POST['submitted'])) // Handle the form.
{
// Check for a URL title.
if(!empty($_POST['race_name']))
{
$rn = escape_data($_POST['race_name']);
}
else
{
$rn = FALSE;
echo '<p><font color="red">Please enter a Race Name.</font></p>';
}
if($rn) // If everything is filled in and OK.
{
// Add the user.
$raceid = @mysql_insert_id();
$query = "INSERT INTO races (race_name) VALUES ('$rn')";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
$raceid = @mysql_insert_id();
if($raceid > 0) // New URL has been added.
{
// Make the URL associations.
// Build query.
$query = 'INSERT INTO races (raceid) VALUES';
$query .= "($raceid), ";
$result = @mysql_query($query); // run the query.
// Send the email.
$body = "Thank you for posting a new Race.\n\n";
mail($_POST['dhoracek1@cox.net'], 'Registration Confirmation', $body, 'From: info@vanguardlibrary.com');
}
}
}
?>
<form action="race.php" method="post">
Race Name:
<input name="race_name" type="text" size="10" maxlength="20" value="<?php if(isset($_POST['race_name'])) echo $_POST['race_name']; ?>">
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
mysql_close(); // Close the database connection.
?>
|
I can get it to work just fine adding race_name and auto incrementing.
Here is my vbulletin RACESUBMIT template
Quote:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title><phrase 1=$vboptions[bbtitle]>$vbphrase[x_powered_by_vbulletin]</phrase></title>
$headinclude
</head>
<body>
$header
$navbar
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<form action="racesubmit.php" method="post">
Race Name:
<input name="race_name" type="text" size="10" maxlength="20" >
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
</td>
</tr>
</table>
$footer
</body>
</html>
|
NOTE the value of the race_name field is not:
value="<?php if(isset($_POST['race_name'])) echo $_POST['race_name']; ?>
Anyw ay I can get my template file to allow me to add php into the template?
Here is my vbulletin code that formats my form into my vbulletin format.
Quote:
<?php
/* ADDED BY SOKOL for vba modules in forums */
define('VBA_PORTAL', true);
define('VBA_PAGE', 'include');
/* END ADD -SOKOL- */
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'racesubmit'); // 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(
'RACESUBMIT',
);
// pre-cache templates used by specific actions
$actiontemplates = array(
);
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = array();
$navbits[$parent] = 'Race Submit';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('RACESUBMIT') . '");');
// ################################################## #####################
// ######################## START DB SCRIPT ############################
// ################################################## #####################
// This page allows users to add URL's to the database.
require_once('includes/mysql_connect.php'); //connect to the database [NOTE: change to default dir "../includes/mysql_connect" for production site.
if(isset($_POST['submitted'])) // Handle the form.
{
// Check for a URL title.
if(!empty($_POST['race_name']))
{
$rn = escape_data($_POST['race_name']);
}
else
{
$rn = FALSE;
echo '<p><font color="red">Please enter a Race Name.</font></p>';
}
if($rn) // If everything is filled in and OK.
{
// Add the user.
$raceid = @mysql_insert_id();
$query = "INSERT INTO races (race_name) VALUES ('$rn')";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
$raceid = @mysql_insert_id();
if($raceid > 0) // New URL has been added.
{
// Make the URL associations.
// Build query.
$query = 'INSERT INTO races (raceid) VALUES';
$query .= "($raceid), ";
$result = @mysql_query($query); // run the query.
// Send the email.
$body = "Thank you for posting a new Race.\n\n";
mail($_POST['dhoracek1@cox.net'], 'Registration Confirmation', $body, 'From: info@vanguardlibrary.com');
}
}
}
?>
<form action="racesubmit.php" method="post">
Race Name:
<input name="race_name" type="text" size="10" maxlength="20" value="<?php if(isset($_POST['race_name'])) echo $_POST['race_name']; ?>">
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
mysql_close(); // Close the database connection.
?>
|
So now my form displays:
http://vanguardlibrary.com/racesubmit.php
and it seems to submit, but it will not update the database, and I'm assuming it's due to my RACESUBMIT template.
Any ideas?
Thanks a bunch,
Sokol