PHP&HTML Script cut in PHP and Template file help

Discussion forum for MOD Writers regarding MOD Development.
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Hello,

i need a little bit help :) I found in the sourcemod forum the following script and now i want to take this script to integrate it in phpbb3. my problem is the part with the html/php mix because i don't know how to cutting it.

Code: Select all

<?php
    //Database Info
    $host = ''; //SQL server host, usually localhost
    $user = ''; //The user to access the database
    $pass = ''; //The password to access the database
    $db = ''; //The database name of sourcebans
    $sourcebans = ''; //Link to your Sourcebans install (required for the country flags, with a trailing slash)
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Bans</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            #flags{text-align: center;}
            #table{margin-right: auto; margin-left: auto;}
            table, th, td{border: 1px solid black;}
        </style>
    </head>
    <body>
        <?php
            //Connect to the SQL server and select the database...
            mysql_connect($host, $user, $pass) or die('Couldn\'t connect to the MySQL server.');
            mysql_select_db($db) or die('Couldn\'t select the database.');
			
            function SecondsToString($sec, $textual=true){
                if($textual) {
					$div = array( 2592000, 604800, 86400, 3600, 60, 1 );
					$desc = array('mo','wk','d','hr','min','sec');
					$ret = null;
					foreach($div as $index => $value){
						$quotent = floor($sec / $value); //greatest whole integer
						if($quotent > 0) {
							$ret .= "$quotent {$desc[$index]}, ";
							$sec %= $value;
						}
					}
					return substr($ret,0,-2);
				} else {
					$hours = floor ($sec / 3600);
					$sec -= $hours * 3600;
					$mins = floor ($sec / 60);
					$secs = $sec % 60;
					return "$hours:$mins:$secs";
                }
            }
			
            $result = mysql_query("SELECT 
			                        b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
								    CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST('76561197960265728' AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id, 
								    a.user AS admin_name 
								  FROM 
								    `sb_bans` b 
									LEFT JOIN 
									  `sb_admins` a 
									ON 
									  a.aid = b.aid 
								  ORDER BY 
								    `created` DESC
								  LIMIT 0,30");
            echo '<table id="table">
            <tr>
            <th>Country</th>
            <th>Date</th>
            <th style="text-align: left;">Player</th>
            <th>Reason</th>
            <th>Admin</th>
            <th>Length</th>
            </tr>';
            while($row = mysql_fetch_array($result)) {
				// Remove whitespace
				array_walk($row, "trim");
				echo "<tr>";
				#Country...
				if(!empty($row['country']) && $row['country'] != ' ') {
					echo "<td id=\"flags\">" . '<img src="'.$sourcebans.'images/country/'.strtolower($row['country']).'.gif" />'. "</td>";
				}
				else {
					echo "<td id=\"flags\">" . '<img src="'.$sourcebans.'images/country/zz.gif" />'. "</td>";
				}
				#End country, begin date...
				echo "<td>" . date('d/m/Y', $row['created']) . "</td>";
				#Player name...
				if(!empty($row['name']) && $row['name'] != ' ') {
					echo "<td>" . '<a href="http://steamcommunity.com/profiles/'.$row['community_id'].'" target="_blank">'.$row['name'].'</a>' . "</td>";
				}
				else {
					echo "<td>" . '<i>No nickname present</i>' . "</td>";
				}
				#Reason...
				if(!empty($row['reason']) && $row['reason'] != ' ') {
					echo "<td>" . $row['reason'] . "</td>";
				}
				else{
					echo "<td>" . '<i>No reason present</i>' . "</td>";
				}
				#Admin name...
				echo "<td>" . $row['admin_name'] . "</td>";
				#Length of ban...
				if($row['length'] == 0) {
					echo "<td>" . 'Permanent '.$row['RemoveType'] . "</td>";
				} else {
					echo "<td>" . SecondsToString($row['length']).(empty($row['RemoveType'])?'':' (' . $row['RemoveType'] . ')').'</td>';
				}
				echo "</tr>";
            }
            echo "</table>";
        ?>
    </body>
</html>
hope someone can help
Last edited by Angel200 on Mon Mar 05, 2012 11:19 am, edited 1 time in total.
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: Sourcemod integration help

Post by Angel200 »

PLS, i can only a few php things and this is a little bit to hard for me. :cry: :cry:
So I need only the following part which is the part for the template file but i don't now how to make it :( that the HTMl-Part is in template and the PHP-Part points on the HTML-Part in the template

Code: Select all

$result = mysql_query("SELECT
                                 b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
                            CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST('76561197960265728' AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id,
                            a.user AS admin_name
                          FROM
                            `sb_bans` b
                           LEFT JOIN
                             `sb_admins` a
                           ON
                             a.aid = b.aid
                          ORDER BY
                            `created` DESC
                          LIMIT 0,30");
            echo '<table id="table">
            <tr>
            <th>Country</th>
            <th>Date</th>
            <th style="text-align: left;">Player</th>
            <th>Reason</th>
            <th>Admin</th>
            <th>Length</th>
            </tr>';
            while($row = mysql_fetch_array($result)) {
            // Remove whitespace
            array_walk($row, "trim");
            echo "<tr>";
            #Country...
            if(!empty($row['country']) && $row['country'] != ' ') {
               echo "<td id=\"flags\">" . '<img src="'.$sourcebans.'images/country/'.strtolower($row['country']).'.gif" />'. "</td>";
            }
            else {
               echo "<td id=\"flags\">" . '<img src="'.$sourcebans.'images/country/zz.gif" />'. "</td>";
            }
            #End country, begin date...
            echo "<td>" . date('d/m/Y', $row['created']) . "</td>";
            #Player name...
            if(!empty($row['name']) && $row['name'] != ' ') {
               echo "<td>" . '<a href="http://steamcommunity.com/profiles/'.$row['community_id'].'" target="_blank">'.$row['name'].'</a>' . "</td>";
            }
            else {
               echo "<td>" . '<i>No nickname present</i>' . "</td>";
            }
            #Reason...
            if(!empty($row['reason']) && $row['reason'] != ' ') {
               echo "<td>" . $row['reason'] . "</td>";
            }
            else{
               echo "<td>" . '<i>No reason present</i>' . "</td>";
            }
            #Admin name...
            echo "<td>" . $row['admin_name'] . "</td>";
            #Length of ban...
            if($row['length'] == 0) {
               echo "<td>" . 'Permanent '.$row['RemoveType'] . "</td>";
            } else {
               echo "<td>" . SecondsToString($row['length']).(empty($row['RemoveType'])?'':' (' . $row['RemoveType'] . ')').'</td>';
            }
            echo "</tr>";
            }
            echo "</table>";
        ?>
oh and i need a part where i can point on a Sub-Forum with a link
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Brf »

Seriously, you are much better-off looking for a mod written for phpBB that does what you are looking to add. The type of script you are working with does not work very well with the phpBB template system.
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

The Problem is there is no other script this is the only one i found.
So many people ask for a integration in phpbb in the sourcebans forum but this is all we have

Edit: ok i found one for webspell, is that better?

Code: Select all

<?
/**************************************
 Team-WB Lastban SC File
 Shows last Sourceban's-Entry's
 
 © 2010 www.team-wb.de

 For JS-Tooltip add the following line
 to your <head>:

 <script type="text/javascript" src="js/starter/script.js"></script>


**************************************/
include('_mysql.php');


/**************************************
 Change Sourceban-Database-Settings
 for your server!
**************************************/
DEFINE('SB_DB', 'sourceban_sb'); //Database for sourceban
DEFINE('SB_DB_USER', 'USER'); //User for sourceban-database
DEFINE('SB_DB_PASS', 'PASS'); //Password for sourceban-database
DEFINE('SB_PREFIX', '_sb_'); // Sourceban-Table PREFIX
DEFINE('MAX_ENTRYS', "5"); // Numbers of bans shown on page
DEFINE('SOURCEBAN_URL', 'http://sourceban.team-wb.de/index.php?p=home'); //Url to your Sourceban-Page

?>





<?
	//Connect to sourceban-db
	if($db != SB_DB){
				
		mysql_connect($host, SB_DB_USER, SB_DB_PASS) OR system_error('ERROR: Can not connect to MySQL-Server');
		mysql_select_db(SB_DB) OR die("fehler: konnte DB nicht finden");
	}									
	$SQL = safe_query("SELECT * FROM ".SB_PREFIX."bans ORDER BY bid DESC LIMIT ".MAX_ENTRYS."");
	$error = mysql_error();
	if($SQL){
		while($row=mysql_fetch_array($SQL)){
			$createdate = date("d.m.Y, H:i",$row[created]);
			echo'
			<div class="headline" style="line-height:16px;" onmouseover="this.className=\'headline_over\'" onmouseout="this.className=\'headline\'" onclick="window.location=\'http://sourceban.team-wb.de/index.php?p=home\'">
				<div style="float:left;line-height:16px;margin-top:7px;width:20px;"><img src="images/ban.png" alt="" /></div>
				<div style="float:left">
					<small>'.$createdate.'</small><br/>
					<a href="'.SOURCEBAN_URL.'" target="_blank" onmouseover="tooltip.show(\'<b>'.$row[name].'</b><br />Reason: '.$row[reason].'\', 200);" onmouseout="tooltip.hide();">'.$row[name].'</a><br />
				</div>
				<div style="clear:both"></div>
			</div>';
		}
	}else{
		echo"Fehler: $error";
	}
	$sql2 = safe_query("SELECT * FROM  ".SB_PREFIX."bans");
	$data = mysql_fetch_array($sql2);
	$datum = date("d.m.Y",mktime());
	$sql3 = safe_query("SELECT created FROM ".SB_PREFIX."bans");									
	$i=0;
	while($today = mysql_fetch_array($sql3)){
		$createdate = date("d.m.Y",$today[created]);
		if($datum == $createdate){
			$i++;
		}
	}

	//reconnect to webspell-db
	if($db != SB_DB){
		
		mysql_connect($host, $user, $pwd) or system_error('ERROR: Can not connect to MySQL-Server');
		mysql_select_db($db) or system_error('ERROR: Can not connect to database "'.$db.'"');

		mysql_query("SET NAMES 'utf8'");
		mysql_select_db($db);
	}
?>	
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Brf »

What are y9ou trying to accomplish, and have you searched the mods database yet?
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Yes i searched the Mod Database result is "Search found 0 matches: sourcebans"

I want the last 30 bans from sourcebans in a external site which is integrated in phpbb3 because it looks well-arranged as the sourcebans site

Sourcebans Site: http://www.taverne-gaming.eu/sourcebans ... php?p=home
Script from from first post: Image

What i make is the bans.php for phpbb

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('common');     

page_header($user->lang['BANS']);

//Database Info
    $host = 'localhost'; //SQL server host, usually localhost
    $user = 'blablablub'; //The user to access the database
    $pass = 'blablablub'; //The password to access the database
    $db = 'sourcebans'; //The database name of sourcebans
    $sourcebans = './sourcebans/'; //Link to your Sourcebans install (required for the country flags, with a trailing slash)

	//Connect to the SQL server and select the database...
	mysql_connect($host, $user, $pass) or die('Couldn\'t connect to the MySQL server.');
	mysql_select_db($db) or die('Couldn\'t select the database.');

	function SecondsToString($sec, $textual=true){
		if($textual) {
			$div = array( 2592000, 604800, 86400, 3600, 60, 1 );
			$desc = array('mo','wk','d','hr','min','sec');
			$ret = null;
			foreach($div as $index => $value){
			$quotent = floor($sec / $value); //greatest whole integer
			
				if($quotent > 0) {
					$ret .= "$quotent {$desc[$index]}, ";
					$sec %= $value;
				}
			}
		
			return substr($ret,0,-2);
		} 
		else {
			$hours = floor ($sec / 3600);
			$sec -= $hours * 3600;
			$mins = floor ($sec / 60);
			$secs = $sec % 60;
			return "$hours:$mins:$secs";
		}
	}
	$result = mysql_query("SELECT 
			                        b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
								    CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST('76561197960265728' AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id, 
								    a.user AS admin_name 
								  FROM 
								    `sb_bans` b 
									LEFT JOIN 
									  `sb_admins` a 
									ON 
									  a.aid = b.aid 
								  ORDER BY 
								    `created` DESC
								  LIMIT 0,30");
            echo '<table id="table">
            <tr>
            <th>Country</th>
            <th>Date</th>
            <th style="text-align: left;">Player</th>
            <th>Reason</th>
            <th>Admin</th>
            <th>Length</th>
<th>Portest</th>
            </tr>';
            while($row = mysql_fetch_array($result)) {
				// Remove whitespace
				array_walk($row, "trim");
				echo "<tr>";
				#Country...
				if(!empty($row['country']) && $row['country'] != ' ') {
					echo "<td id=\"flags\">" . '<img src="'.$sourcebans.'images/country/'.strtolower($row['country']).'.gif" />'. "</td>";
				}
				else {
					echo "<td id=\"flags\">" . '<img src="'.$sourcebans.'images/country/zz.gif" />'. "</td>";
				}
				#End country, begin date...
				echo "<td>" . date('d/m/Y', $row['created']) . "</td>";
				#Player name...
				if(!empty($row['name']) && $row['name'] != ' ') {
					echo "<td>" . '<a href="http://steamcommunity.com/profiles/'.$row['community_id'].'" target="_blank">'.$row['name'].'</a>' . "</td>";
				}
				else {
					echo "<td>" . '<i>No nickname present</i>' . "</td>";
				}
				#Reason...
				if(!empty($row['reason']) && $row['reason'] != ' ') {
					echo "<td>" . $row['reason'] . "</td>";
				}
				else{
					echo "<td>" . '<i>No reason present</i>' . "</td>";
				}
				#Admin name...
				echo "<td>" . $row['admin_name'] . "</td>";
				#Length of ban...
				if($row['length'] == 0) {
					echo "<td>" . 'Permanent '.$row['RemoveType'] . "</td>";
				} else {
					echo "<td>" . SecondsToString($row['length']).(empty($row['RemoveType'])?'':' (' . $row['RemoveType'] . ')').'</td>';
				}
echo "<td>" . '<a href="http://localhost/phpbb3/viewtopic.php?f=2&t=1&p=2#p2">Protest the Ban</a>' . "</td>";
				echo "</tr>";
            }
            echo "</table>";

// Part for phpbb3 template poniter
/* 
while ($row = $db->sql_fetchrow($result))
{
	$template->assign_block_vars('bans', array(
		'BAN_COUNTRY'		=> $row['ban_country'], // only place holder
		'BAN_DATE'		=> $row['ban_date'], // only place holder
		'BAN_PLAYER'		=> $row['ban_player'], // only place holder
		'BAN_REASON'		=> $row['bans_reason'], // only place holder
		'BAN_ADMIN'		=> $row['ban_admin'], // only place holder
		'BAN_LENGTH'		=> $row['bans_length'], // only place holder
		'BAN_PROTEST'		=> '<a href="http://localhost/phpbb3/viewtopic.php?f=2&t=1&p=2#p2">$user->lang['PROTEST_BAN']</a>',
	));
}
$db->sql_freeresult($result); 
*/

$template->set_filenames(array(
        'body' => 'bans_body.html',
    ));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();

?>
but the part from my second post makes me headache
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Always the same here and in other phpbb Support Sites :x
No one want help or if someone would help he will money for his/her help :roll:

I need only help with this f*****g part from my second post because it is to hard for me with my little php skills. ;( Also no one will write a script for phpbb 3 :(
User avatar
AmigoJack
Registered User
Posts: 5775
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by AmigoJack »

Always the same here and on other sites:
  • Mixing up positions: you're a requester, not a customer. You haven't paid for anything and everybody on the board is doing it in his free time for not being paid. Don't expect a reaction on an "I want" unless you know a reason that I otherwise overlooked for years.
  • Mixing up projects/techniques: people here are specialized on phpBB, not in wasting time to teach basics of PHP, HTML, SQL, CSS, JS or the concept of server client communication. Why don't you join a PHP community to improve your skills?
  • Mixing up need versus want: you're asking for a complete job to be done, not just specific help on 1 or 2 issues. How does templating work? More info. What is DBAL and how to use it? More info. An all-round example of adding your custom page? More info.
  • Mixing up isolating with reducing: why not separating problems and then solving each one step by step? For some reason all people are only seeing one problem, which is then textually beautified as a "small" one with "a quick" question only. Isn't it logical that this approach does not help at all?
In case you overread it: put up specific questions and code lines, not one for all.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Brf »

Yes. The code you are working with really has nothing to do with phpBB. It is designed to be put in a standard PHP page, which echoes its output, not a script/template system like phpBB. You cannot echo HTML like you are doing in your bans.php. Read the templating article mentioned by AmigoJack or http://wiki.phpbb.com/Tutorial.Template_syntax
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

Brf wrote:You cannot echo HTML like you are doing in your bans.php
Omg you missunderstood me, or do you only see the script and don't read what i wrote in the first two posts?
I don't want to echo the html part in the php file -.-" This is from the original script!

Also i now how to ADD custom pages, also i know how the templates work and how the ACP work.
I wrote this Special Command Site for L4D2 Modded Server MOD with a little bit help from oxpus because i had problem with the right system in the ACP-File. And no one from here said me this as i ask. Why? It was only one sentence :?

I understand only phpbb and i have problems to understand normal php scripts so i don't know how to understand the php & html part.

I know also that this script don't work like it is as a phpbb 3 site but how can i change it that it work?
Because i see only a mysql request from the database of sourcemod and the output in html but is it really so?

my minds for the php page:

Code: Select all

$sql = ' b.country, b.created, b.name, b.reason, b.length, b.RemoveType,
								    CAST(MID(b.authid, 9, 1) AS UNSIGNED) + CAST('76561197960265728' AS UNSIGNED) + CAST(MID(b.authid, 11, 10) * 2 AS UNSIGNED) AS community_id, 
								    a.user AS admin_name 
       `sb_bans` b 
									LEFT JOIN 
									  `sb_admins` a 
									ON 
									  a.aid = b.aid 
								  ORDER BY 
								    `created` DESC
								  LIMIT 0,30";
$result = $db->sql_query($sql);

// Is this right?
while ($row = $db->sql_fetchrow($result))
	{
	   $template->assign_block_vars('bans', array(
		  'BAN_COUNTRY'      => $row['country'],
		  'BAN_DATE'      => $row['created'],
		  'BAN_PLAYER'      => $row['name'],
		  'BAN_REASON'      => $row['reason'],
		  'BAN_ADMIN'      => $row['admin_name'],
		  'BAN_LENGTH'      => $row['length'],
		  'BAN_IDK'			=> $row['RemoveType'],
//		  'BAN_PROTEST'      => '$user->lang['PROTEST_BAN]',
	   ));
	}
	$db->sql_freeresult($result);
And i can take the if-else in the template if i make it correct, or not?
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

AmigoJack wrote:why not separating problems and then solving each one step by step? For some reason all people are only seeing one problem, which is then textually beautified as a "small" one with "a quick" question only. Isn't it logical that this approach does not help at all?[/list] In case you overread it: put up specific questions and code lines, not one for all.
So i separat the problem and since Wed Mar 07, 2012 7:12 pm no help. :(

Ok, test in this time with the code and i get the following error if i only want to connect to the DB

ERROR: Fatal error: Call to a member function sql_query() on a non-object in J:\xampp\htdocs\phpBB3\includes\functions_content.php on line 124

Why did i get this error if the my php-file only connect to the DB?

bans.php

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ownsites');     

page_header($user->lang['BANS']);

	//Database Info
    $host = 'localhost'; //SQL server host, usually localhost
    $user = 'xxxxxx'; //The user to access the database
    $pass = 'xxxxxx'; //The password to access the database
    $db = 'sourcebans'; //The database name of sourcebans
    $sourcebans = 'sourcebans'; //Link to your Sourcebans install (required for the country flags, with a trailing slash)

	//Connect to the SQL server and select the database...
	mysql_connect($host, $user, $pass) or die('Couldn\'t connect to the MySQL server.');
	mysql_select_db($db) or die('Couldn\'t select the database.');

$template->set_filenames(array(
        'body' => 'bans_body.html',
    ));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();

?>
User avatar
AmigoJack
Registered User
Posts: 5775
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by AmigoJack »

Because your script is overwriting a variable already being used by phpBB:

Code: Select all

$db = 'sourcebans'; //The database name of sourcebans  
Use less trivial names or even better: capsulate your code inside a function, e.g.:

Code: Select all

  function MyDbConnect() {
    //Database Info
    $host= 'localhost'; //SQL server host, usually localhost
    $user= 'xxxxxx'; //The user to access the database
    $pass= 'xxxxxx'; //The password to access the database
    $db= 'sourcebans'; //The database name of sourcebans
    $sourcebans= 'sourcebans'; //Link to your Sourcebans install (required for the country flags, with a trailing slash)

    //Connect to the SQL server and select the database...
    mysql_connect( $host, $user, $pass ) or die( 'Connect failed' );
    mysql_select_db( $db) or die( 'Selecting database failed' );
  }

  MyDbConnect(); 
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
User avatar
T0ny
Registered User
Posts: 1383
Joined: Sun Jan 29, 2006 8:42 pm
Location: Lancashire
Name: Tony

Re: PHP&HTML Script cut in PHP and Template file help

Post by T0ny »

ERROR: Fatal error: Call to a member function sql_query() on a non-object in J:\xampp\htdocs\phpBB3\includes\functions_content.php on line 124

Why did i get this error if the my php-file only connect to the DB?
because your code overwrites the phpbb $db object

Code: Select all

$db = 'sourcebans'; //The database name of sourcebans
Angel200
Registered User
Posts: 26
Joined: Fri Apr 28, 2006 11:19 am
Location: 127.0.0.1:1337
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by Angel200 »

ok, i changed it in both lines to $sourcedb but i think phpbb don't like it if i want to connect to an other mysql table -.-"
General Error
SQL ERROR [ mysql4 ]

Table 'sourcebans.phpbb_forums' doesn't exist [1146]

SQL

SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id FROM phpbb_forums ORDER BY left_id ASC

BACKTRACE

FILE: [ROOT]/includes/db/mysql.php
LINE: 175
CALL: dbal->sql_error()

FILE: [ROOT]/includes/functions_content.php
LINE: 124
CALL: dbal_mysql->sql_query()

FILE: [ROOT]/bans.php
LINE: 85
CALL: make_jumpbox()
User avatar
AmigoJack
Registered User
Posts: 5775
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: PHP&HTML Script cut in PHP and Template file help

Post by AmigoJack »

phpBB doesn't expect another database than the one it selected - you're selecting one, phpBB another. Would be much easier if you'd use DBAL from the very beginning:

Code: Select all

$dbSourceBan= new $sql_db();  // New DBAL instance
$dbSourceBan-> sql_connect( 'localhost', 'user', 'pass', 'sourcebans', $dbport, FALSE, defined( 'PHPBB_DB_NEW_LINK' )? PHPBB_DB_NEW_LINK: FALSE );  // Actual connection with details

$sql= 'SELECT * FROM table';  // Query command
$result = $dbSourceBan-> sql_query( $sql );
while( $row= $dbSourceBan-> sql_fetchrow( $result ) ) {  // Enumerate zero to many result sets
  print_r( $row );
}
$dbSourceBan-> sql_freeresult( $result );  // Release memory 
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
Locked

Return to “[3.0.x] MOD Writers Discussion”