Include poll with external php [SOLVED]

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Include poll with external php [SOLVED]

Post by isac »

Hi all,

I have a small problem when I tried to include an external file with this code:

Code: Select all

<?php

/* path */
$poll_path = "D:/myclient/sondagem";

require $poll_path."/include/config.inc.php";
require $poll_path."/include/$POLLDB[class]";
require $poll_path."/include/class_poll.php";
$CLASS["db"] = new polldb_sql;
$CLASS["db"]->connect();

$php_poll = new poll();

/* the third poll */
$php_poll->set_template_set("popup");
if ($php_poll->is_valid_poll_id(3)) {
    echo $php_poll->display_poll(3);
}

?>
I called call.poll.php (Yes is a poll script by proxy2.de) but i got this error

Code: Select all

Database Error

MySQL Error : Database Error
Error Number: 1046 No Database Selected
Date        : Mon, August 23, 2004 19:49:58
IP          : 127.0.0.11
Browser     : Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040614 Firefox/0.9
Referer     : 
PHP Version : 4.3.6
OS          : WINNT
Server      : Apache/2.0.50 (Win32) mod_ssl/2.0.50 OpenSSL/0.9.7d PHP/4.3.6
Server Name : myclient
Script Name : /index.php
In my template I put this code, but gives me the above error

Code: Select all

{PHP:sondagem/call.poll.php}
but if I type in browser adress bar, its works!!!

Thank You
Isac.

this is class_mysql.php file called by
require $poll_path."/include/$POLLDB[class]";

Code: Select all

<?php
/**
 * ----------------------------------------------
 * Advanced Poll 2.0.3 (PHP/MySQL)
 * Copyright (c)2001 Chi Kien Uong
 * URL: http://www.proxy2.de
 * ----------------------------------------------
 */

class polldb_sql {

    var $conn_id;
    var $result;
    var $record;
    var $db;
    var $port;
    var $query_count;

    function polldb_sql() {
        global $POLLDB;
        $this->query_count=0;
        $this->db = $POLLDB;
        if(ereg(":",$this->db['host'])) {
            list($host,$port) = explode(":",$this->db['host']);
            $this->port = $port;
        } else {
            $this->port = 3306;
        }
    }

    function connect() {
        $this->conn_id = mysql_connect($this->db['host'].":".$this->port,$this->db['user'],$this->db['pass']);
        if ($this->conn_id == 0) {
            $this->sql_error("Connection Error");
        }
        if (!mysql_select_db($this->db['dbName'], $this->conn_id)) {
            $this->sql_error("Database Error");
        }
        return $this->conn_id;
    }

    function query($query_string) {
        $this->result = mysql_query($query_string,$this->conn_id);
        $this->query_count++;
        if (!$this->result) {
            $this->sql_error("Query Error");
        }
        return $this->result;
    }

    function fetch_array($query_id) {
        $this->record = mysql_fetch_array($query_id,MYSQL_ASSOC);
        return $this->record;
    }

    function num_rows($query_id) {
        return ($query_id) ? mysql_num_rows($query_id) : 0;
    }

    function num_fields($query_id) {
        return ($query_id) ? mysql_num_fields($query_id) : 0;
    }

    function free_result($query_id) {
        return mysql_free_result($query_id);
    }

    function affected_rows() {
        return mysql_affected_rows($this->conn_id);
    }

    function close_db() {
        if($this->conn_id) {
            return mysql_close($this->conn_id);
        } else {
            return false;
        }
    }

    function sql_error($message) {
        $description = mysql_error();
        $number = mysql_errno();
        $error ="MySQL Error : $message\n";
        $error.="Error Number: $number $description\n";
        $error.="Date        : ".date("D, F j, Y H:i:s")."\n";
        $error.="IP          : ".getenv("REMOTE_ADDR")."\n";
        $error.="Browser     : ".getenv("HTTP_USER_AGENT")."\n";
        $error.="Referer     : ".getenv("HTTP_REFERER")."\n";
        $error.="PHP Version : ".PHP_VERSION."\n";
        $error.="OS          : ".PHP_OS."\n";
        $error.="Server      : ".getenv("SERVER_SOFTWARE")."\n";
        $error.="Server Name : ".getenv("SERVER_NAME")."\n";
        $error.="Script Name : ".getenv("SCRIPT_NAME")."\n";
        echo "<b><font size=4 face=Arial>$message</font></b><hr>";
        echo "<pre>$error</pre>";
        exit();
    }

}

?>
Last edited by isac on Mon 23. Aug 2004, 21:17, edited 2 times in total.
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Does changing this make a difference?
"config.inc.php"

Code: Select all

$phpwcms["allow_remote_URL"]  = 0;        //0 = no remote URL in {PHP:...} replacement tag allowed, 1 = allowed
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

Hi DeXXus

No :cry:
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Hi back Isac,
What are you typing into the browser (that works?)

{PHP:whatever I'm typing into the browser}

Surely it's not "http://sondagem/call.poll.php"
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

DeXXus You are right!!!

if I put this

{PHP:http://myclient/sondagem/call.poll.php}

works very well.

Thank You one more time
alchemistkevin
Posts: 15
Joined: Sun 11. Apr 2004, 22:09
Location: London
Contact:

Post by alchemistkevin »

Thanks Guys!!!

I've installed the same module and using tips gained from here :)) been able to get the info onto my website in my default template in a matter of 30 mins :)

http://www.alternateplanet.net

(haven't defined polls to be reachable through the menu structure)
in an alternate time
Post Reply