1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help

Discussion in 'PHP' started by Pyramid Games Ltd., Aug 24, 2007.

  1. Pyramid Games Ltd.

    Pyramid Games Ltd. New Member

    Joined:
    Aug 24, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    United States
    Home Page:
    Warning: require_once(DbConnector.php) [function.require-once]: failed to open stream: No such file or directory in /home/zendurl/public_html/p/program5/signup.php on line 21

    Fatal error: require_once() [function.require]: Failed opening required 'DbConnector.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/zendurl/public_html/p/program5/signup.php on line 21

    The file (signup.php):
    PHP:
    <form action="signup.php?submit" class='form colours' method='POST'>
        <fieldset>
            <legend>Join Programmer's Space</legend>
                <p align='right'>Username: <input name='username' size='25' maxlength='25' /></p>            
                <p align='right'>Password: <input name='password' size='25' maxlength='25' /></p>    
                            <p align='right'><input type='submit' value='Submit' /></p>
        </fieldset>
    </form>
    <?php
    // Check if the form has been submitted
    if(isset($_GET["submit"]))
    {
        if(isset(
    $_POST["username"]) && isset($_POST["password"]))
        {    
            
    //Username or password is not blank
            
    if($_POST["username"]!="" && $_POST["password"]!="")
            { 
    // Everything is ok add the user to the database
     
                // Connect to the database
                
    require_once("DbConnector.php");   // Include the database class
                
    $db = new DbConnector();               // Create an instance of the database class
                
    $db->connect();                               // Connect to the database
                
    $query "SELECT * FROM members WHERE username='".$_POST["username"]."'";
                
    $result $db->query($query);
                
    $result mysql_num_rows($result);
     
                if(
    $result!="0")
                    echo 
    "Username already exists!";
                else 
                { 
                    
    // Create a query that inserts the data from the form to the database
                    
    $query "INSERT INTO members(username,password) VALUES('".$_POST["username"]."','".$_POST["password"]."')";
     
                    
    $result $db->query($query);
                    echo 
    "Signed up succesfully you can now <a href=\"login.php\">log in</a>";
                }
            }
            else 
            {
                echo 
    "Error: No username or password supplied, try again.";
            }
     
        }
        else 
            echo 
    "Error: please fill in the <a href=\"signup.php\">signup form</a>";
    }
    ?>
    DBConnector.php
    PHP:
    <?php
    ////////////////////////////////////////////////////////////////////////////////////////
    // Class: DbConnector
    ///////////////////////////////////////////////////////////////////////////////////////
    require_once 'DbVars.php';
     
    class 
    DbConnector extends Dbvars {
     
            var 
    $theQuery;
            var 
    $link;
      var 
    $dbname;
      var 
    $host;
      var 
    $user;
      var 
    $pass;
        
       function 
    DbConnector(){
            
    // Load settings from parent class
            
    $settings Dbvars::getSettings();
            
    // Get the main settings from the array we just loaded
            
    $this->host $settings['dbhost'];
            
    $this->dbname $settings['dbname'];
            
    $this->user $settings['dbusername'];
            
    $this->pass $settings['dbpassword'];
        }
      
       function 
    setDatabase($ndbname)
      {
        
    $this->dbname $ndbname;
      }
      
      function 
    connect()
      {
                     
    // Connect to the database
                     
    $this->link mysql_connect($this->host$this->user$this->pass)or die(mysql_error());
                     
    mysql_select_db($this->dbname);
      }
     
        function 
    query($query) {
     
            
    $this->theQuery $query;
            
    $res mysql_query($query$this->link)or die(mysql_error());
      return 
    $res;
     
        }
     
        function 
    fetchArray($result) {
     
           return 
    mysql_fetch_array($result);
     
        }
     
    }
    ?>
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    The problem is with the location of DBConnector.php, either copy it to the same folder as the othe file of provide the full path to DBConnector.php
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Try giving better titles and that would give you better responses. I would suggest you read [thread=168]Before you make a query[/thread].
     

Share This Page