I developed this class, I wonder if there's anything "wrong" or that I can improve.
Thanks in advance.
Code: Select all
<?php
class network {
public $userID;
public $schoolID;
public $userEnrollment;
public $userName;
public $userPass;
public $dbHost;
public $dbUser;
public $dbName;
public $dbPass;
public $dbUserTable;
public $dbSchoolTable;
function dbInfo() {
$this->dbHost = 'localhost';
$this->dbUser = '';
$this->dbPass = '';
$this->dbName = '';
$this->dbUserTable = '';
$this->dbSchoolTable = '';
}
function registerUser($userEnrollment, $userName, $userPass) {
$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
if(!$dbLink) die("Could not connect to database: " . mysql_error());
mysql_select_db($this->dbName);
$query = "INSERT INTO $this->dbUserTable VALUES (NULL, \"$userEnrollment\", \"$userName\", \"$userPass\")";
$result = mysql_query($query);
if(!$result) {
echo "Fail.";
} else {
$this->userID = mysql_insert_id();
}
mysql_close($dbLink);
$this->userName = $userName;
$this->userPass = $userPass;
}
function registerSchool($schoolName) {
$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
if(!$dbLink) die("Could not connect to database: " . mysql_error());
mysql_select_db($this->dbName);
$query = "INSERT INTO $this->dbSchoolTable VALUES (NULL, \"$schoolName\")";
$result = mysql_query($query);
if(!$result) {
echo "Fail.";
} else {
$this->schoolID = mysql_insert_id();
}
mysql_close($dbLink);
$this->schoolName = $schoolName;
}
function userLogin() {
$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
if(!$dbLink) die("Could not connect to database: " . mysql_error());
mysql_select_db($this->dbName);
$query = "SELECT * FROM $this->dbUserTable WHERE userEnrollment = \"$this->userEnrollment\" AND userPass = \"$this->userPass\" LIMIT 1";
$result = mysql_query($query);
if(!$result) {
echo "Fail.";
} else {
$row = mysql_fetch_array($result);
session_regenerate_id();
$_SESSION['userEnrollment'] = $this->userEnrollment;
session_write_close();
}
mysql_close($dbLink);
}
function changePass($newPass) {
$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
if(!$dbLink) die("Could not connect to database: " . mysql_error());
mysql_select_db($this->dbName);
$query = "SELECT * FROM $this->dbUserTable WHERE userName = \"$this->userName\" LIMIT 1";
$result = mysql_query($query);
if(!$result) {
echo "Fail.";
} else {
$query = "UPDATE $this->dbUserTable SET userPass = \"$newPass\" WHERE userName = \"$this->userName\"";
$result = mysql_query($query);
if(!$result) {
echo "Fail";
} else {
$this->userPass = $newPass;
}
}
mysql_close($dbLink);
}
}
?>