View Single Post
  #3  
Old 08-05-2006, 12:14 AM
sokol sokol is offline
 
Join Date: Jun 2004
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>&nbsp;

<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
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01251 seconds
  • Memory Usage 1,820KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete