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 Code:
<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>";
}
?>
PHP Code:
<?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);
}
}
?>

