Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-02-24 10:27:31

neoformat
Member
From: Russia
Registered: 2007-02-17
Posts: 37
Website

Problem with including PHP script

Hello,

I use cool PHP guestbook @lex Guestbook and in a database there are a lot of comments that I dont want to loose. I have tried to put this guestbook to the textpattern page:

It works fine when I open it from the directory where it is installed, but when I insert it to page:

code
<!— center —>

<div id=content>

<txp:php>

$wd_was = getcwd();
chdir(‘/srv1/www/dimasnet.com/subdomains/www/book’);
include(‘index.php’);
chdir($wd_was);

</txp:php>

</div>
code

in result I have white blank screen with error:

bold
Fatal error: Call to a member function on a non-object in /srv1/www/dimasnet.com/subdomains/www/book/include/funct_sql_admin.php on line 24
bold

Here is funct_sql_admin.php content:

code
<?php
///////////////////////////////////////////////
// @lex Guestbook //
// by Soulard Alexis © 2002 – 2006 //
// http://www.alexphpteam.com/ //
// all right reserved //
///////////////////////////////////////////////

function countTotal($count, $table, $where=”“, $jointure=”“, $as=”“){ global $f_db_connexion, $name_table, $idc;

$query = “SELECT COUNT FROM `”.$name_table[$table].”` “.$as.” “.$jointure.” “.$where; $result = $f_db_connexion -> sql_query($query); $row = $f_db_connexion -> sql_fetchrow($result); return $row0;
}

// ——-

function sql_select_query($champs, $table, $where=”“, $orderby=”“, $limit=”“, $traitement_messages=false, $jointure=”“, $as=”“, $prefix=”“){ global $f_db_connexion, $name_table, $htmlspecial, $exact_name, $debug, $no_count, $idc, $indice_start, $not_init_tab;

$query = “SELECT “.$champs.” FROM `”.$name_table[$table].”` “.$as.” “.$jointure.” “.$where.” “.$orderby.” “.$limit; $result = $f_db_connexion -> sql_query($query); global ${“nb_champs_”.$table.(($prefix) ? $prefix : “”)};

if (!$no_count) ${“nb_champs_”.$table.(($prefix) ? $prefix : “”)} = $f_db_connexion -> sql_numrows($result);

if (!isset($indice_start) || !$indice_start){ $i=1; $val_start = 1; } else if ($indice_start){ $i=$indice_start; $val_start = $indice_start; }

while ($row = $f_db_connexion -> sql_fetchrow($result)){ foreach ($row as $cle => $value){ if ($cle == “0” || trim((int)$cle)) continue;

if ($i == $val_start){ if ($exact_name) global ${$cle}; else { global ${$prefix.$table.”_”.$cle};

if (!isset($not_init_tab)) ${$prefix.$table.”_”.$cle} = array(); } }

if ($traitement_messages && $cle == “message”){ $value = trim($value); $value = cut($value); $value = replace_censure_smileys($value); }

if ($exact_name && $htmlspecial != “no”) ${$cle} = $value; else if ($exact_name) ${$cle} = $value; else if ($htmlspecial != “no” && $cle != “code_source”) ${$prefix.$table.”_”.$cle}[$i] = $value; else ${$prefix.$table.”_”.$cle}[$i] = $value; }

$i++; }
}

// ——-

function f_verif_identif(){ global $name_table, $_POST, $f_db_connexion, $id_user;

$query = “SELECT id_user,login FROM “.$name_table[‘alex_livre_users’].” WHERE login=’”.$_POST[‘f_login’].”’ and pass=’”.$_POST[‘f_pass’].”’”; $result = $f_db_connexion -> sql_query($query);

$row = $f_db_connexion -> sql_fetchrow($result); $id_user = $row0; return $row1;
}

// ——-

function f_insert_session($f_sid, $type_action, $id_user, $login_user){ global $f_db_connexion, $name_table;

switch ($type_action){ case(“insert”): $query = “INSERT INTO “.$name_table[‘alex_livre_sessions’].” (session, id_user, login, last_connect) VALUES.”’)”; break; case(“update”): $query = “UPDATE “.$name_table[‘alex_livre_sessions’].” SET last_connect=’”.time().”’ WHERE session=’$f_sid’”; break; }

$result = $f_db_connexion -> sql_query($query);
}

// ——-

function f_destroy_session(){ global $f_db_connexion, $name_table, $f_temps_session;

$actu_time = time(); $query = “DELETE FROM “.$name_table[‘alex_livre_sessions’].” WHERE last_connect < ($actu_time – $f_temps_session)”; $result = $f_db_connexion -> sql_query($query);
}

// ——-

function f_verif_session(){ global $_GET, $name_table, $f_db_connexion, $f_temps_session, $id_user, $login_user;

$actu_time = time(); $query = “SELECT id_user, login FROM “.$name_table[‘alex_livre_sessions’].” WHERE session=’”.$_GET[‘f_sid’].”’ and last_connect >= ($actu_time – $f_temps_session)”; $result = $f_db_connexion -> sql_query($query);

if ($row = $f_db_connexion -> sql_fetchrow($result)){ $id_user = $row0; $login_user = $row1;

//on prolonge la session f_insert_session($_GET[‘f_sid’], “update”, $id_user, $login_user); } else{ //destruction de la session et redirection vers la page d’accueil de la partie admin $query = “DELETE FROM “.$name_table[‘alex_livre_sessions’].” WHERE session=’”.$_GET[‘f_sid’]; $result = $f_db_connexion -> sql_query($query);

header(“Location: index.php?close_sess=1”); exit; }
}

// ——-

function f_save_pages(){ global $f_db_connexion, $name_table, $tab_champs_admin, $id_user, $nb_messages_page;

generer_liste_admin();

$query = “SELECT * FROM “.$name_table[‘alex_livre_users’].” WHERE id_user=’”.$id_user.”’”; $result = $f_db_connexion -> sql_query($query);

$a=4; while($row = $f_db_connexion->sql_fetchrow($result)){ for ($i=1; $i<=count($tab_champs_admin); $i++){ global ${“user_”.$tab_champs_admin[$i]};

${“user_”.$tab_champs_admin[$i]} = $row[$tab_champs_admin[$i]]; $a++; }

$nb_messages_page = $row[‘nb_mess_page’]; }
}

// ——-

function moyenne_notes_messages(){ global $name_table, $f_db_connexion, $value_moyenne_notes_messages;

$query = “SELECT AVG FROM “.$name_table[‘alex_livre_messages’].” WHERE note<>’‘”; $result = $f_db_connexion -> sql_query($query);

while ($row = $f_db_connexion->sql_fetchrow($result)){ $value_moyenne_notes_messages = $row0; }
}
?>
code

What is problem??? Why it doesnt work?

Thanks,
Dimas.

Offline

#2 2007-02-24 12:41:28

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Problem with including PHP script

Call to a member function on a non-object…

That means you are trying to run a function on an object that does not exist, one line 24. On line 24 you have:

$result = $f_db_connexion -> sql_query($query);

On line 21 you have:

global $f_db_connexion

Which means the variable is supposed to be coming from outside the function, defined somewhere in the script that includes that file. But, for whatever reason, it isn’t.

That’s all I can offer without knowing all the parts of the script.

You can simplify the PHP you’re using, though. I can’t be sure, but it might be contributing to the problem:

<txp:php>include('/srv1/www/dimasnet.com/subdomains/www/book/index.php');</txp:php>

Offline

#3 2007-02-24 13:02:52

neoformat
Member
From: Russia
Registered: 2007-02-17
Posts: 37
Website

Re: Problem with including PHP script

If I start script in the same directory where is textpattern installed so then guestbook php script starts new setup and cant find setup.php, cos its in/book/ directory… So it is neccesary to change working directory to /book/.

I think that problem in textpattern and his global limitations.

Offline

#4 2007-02-25 17:56:14

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Problem with including PHP script

global limitations? Sounds like you really don’t understand PHP. It means your guestbook script isn’t intended to be included. I just downloaded and looked at the script, and that does appear to be the case.

Offline

Board footer

Powered by FluxBB