TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-23-2007, 04:11 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Installing..

Hey, I got a problem again >.<

PHP Code:
include('core/database.php');
    $step = $_GET['step'];
    
    ?>
    <div class="page">
        <div id="pagetitle">
            <h1>Installing...</h1>
            <hr>
        </div>
        
        <div id="pagestep">
        
    <?php
    
    
switch($step) {
        
        case 
1:
        
        if(!isset(
$_POST['connect'])) {
            
        
?>
        
        <p>Step 1: Database connection</p>
        </div>
        <div id="pageform">
        <form action="<?php $_SERVER['PHPSELF']; ?>" method="POST">
        <div id="pagecat2">Database host:</div>
        <input type="text" name="host" value="localhost">
        <div id="pagecat2">Database user:</div>
        <input type="text" name="user" value="root">
        <div id="pagecat2">Database password:</div>
        <input type="text" name="pass">
        <div id="pagecat2">Database name:</div>
        <input type="text" name="data">
        <input type="submit" value="Connect" name="connect">
        </form></div>
        <?php
        
        
} elseif(isset($_POST['connect'])) {
            
            
$user $_POST['user'];
            
$host $_POST['host'];
            
$pass $_POST['pass'];
            
$data $_POST['data'];
            
            
$test = new    database($host$user$pass$data);
            if(!
$test) {
                
                
?>
                <p>Step 1: Database connection</p>
                <div id="pagecat2">Failed! Check your database again for the correct data.</div>
                <a href="install.php?step=1">Go back</a>
                
                <?php
                
            
}
            
            else {
                
                
?>
                <p>Step 1: Database connection</p>
                <div id="pagecat2">Success! Please click the link in order to proceed.</div>
                <a href="install.php?step=2">Step 2</a>
                
                <?php
                
                $file 
'config.php';
                
$open fopen($file'a');
                
$content 
'<?php 
                
function __autoload($class_name) { 
                    
    require_once \'core/\' . $class_name . \'.php\'; 
                    

                
$system->db = new database(\''
.$host.'\', \''.$user.'\', \''.$pass.'\', \''.$data.'\');';
                            
                
$write fwrite($open$content);
                
fclose($open);
                
            }
        }
        
    }
Basicly, it's this line:
PHP Code:
$test = new    database($host$user$pass$data);
            if(!
$test) { 
What I'm trying to do here is that if the database connection attempt is not successful, then it should do the things inside the brackets of the if(!$test) { }

Database class is like this:
PHP Code:
public function __construct($host$user$pass$db) {
                
            
$this->db['host'] = $host;
            
$this->db['user'] = $user;
            
$this->db['pass'] = $pass;
            
$this->db['db'] = $db;
                
            
$this->connect();
                        
        }

private function 
connect() {
            
            
$connect = @mysql_connect($this->db['host'], $this->db['user'], $this->db['pass']);
            
            if(!
$connect) {
                
                return 
false;
                
            }
            
            else {
                
                
$this->select();
                
            }
              
        }

private function 
select() {
            
            
$select = @mysql_select_db($this->db['db']);
            
            if(!
$select) {
                
                return 
false;
                
            }
            
            else {
                
                return 
true;
                
            }
            
        } 
Tanax is offline  
Reply With Quote
Old 09-23-2007, 05:24 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Looks right to me. What's it not doing?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-23-2007, 05:38 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

The problem is that even if I write a database that doesn't exists, it gives me successful, and writes the config.php file. Which, it shouldn't.

It should only write it if the connecting with the database is successful.
Tanax is offline  
Reply With Quote
Old 09-23-2007, 06:19 PM   #4 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

The problem, as you correctly stated, is this line:

PHP Code:
$test = new    database($host$user$pass$data);
            if(!
$test) { 
I can see that you're testing to see if the database connection was successfull, but what you're actually testing is if the database object exists. The easiest solution (without changing alot of code) would be to simply remove the $this->connect() call from your class' __construct() method and call it after instantiating your class object, changing the current code to:

PHP Code:
$test = new    database($host$user$pass$data);
            if(!
$test->connect()) { 
You will also need to change the scope of the connect() function from private to public.
Karl is offline  
Reply With Quote
Old 09-23-2007, 06:22 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Ah! Thanks! I'll try it asap :)
Tanax is offline  
Reply With Quote
Old 09-23-2007, 06:30 PM   #6 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I got this:
Quote:
Catchable fatal error: Object of class database could not be converted to string in C:\wamp\www\DB Class\install.php on line 56
PHP Code:
if(!$$test->connect()) { 
(line 56)

Edit, ooops!

Saw the error.

Now:
Quote:
Failed! Check your database again for the correct data.
:D:D Thanks!
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:40 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design