Skip to content
Snippets Groups Projects
Commit 7cefa3c2 authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

signup in oops

parent 6c46a622
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ if (isset($_POST['username']) and isset($_POST['password']) and !empty($_POST['p
$password = $_POST['password'];
$email = $_POST['email_address'];
$phone = $_POST['phone'];
$error = signup($username, $password, $email, $phone);
$error = User::signup($username, $password, $email, $phone);
$signup = true;
}
?>
......
<?php
class Database
{
public static $conn = null;
public static function getConnection()
{
if (Database::$conn == null) {
$servername = "mysql.selfmade.ninja";
$username = "sibidharan";
$password = "xyjxo8-xefjat-gYnsif";
$dbname = "sibidharan_newdb";
// Create connection
$connection = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error); //TODO: Replace this with exception handling
} else {
printf("New connection establishing...");
Database::$conn = $connection; //replacing null with actual connection
return Database::$conn;
}
} else {
printf("Returning existing establishing...");
return Database::$conn;
}
}
}
......@@ -16,11 +16,18 @@ class Mic
public $model;
private $light;
public $price;
public static $test;
public static function testFunction()
{
printf("This is a static function, this can be run without object initialization. ");
}
public function __construct($brand)
{
printf("Constructing object...");
$this->brand = ucwords($brand);
Mic::testFunction();
}
public function setLight($light)
......@@ -52,4 +59,22 @@ class Mic
{
return $this->getModel();
}
public function __destruct()
{
printf("Destruct object: brand: $this->brand...");
}
}
class DupMic
{
public static function testFunction()
{
return "hello";
}
}
function testFunction()
{
printf("This is a static function, this can be run without object initialization.");
}
<?php
class User
{
public static function signup($user, $pass, $email, $phone)
{
$conn = Database::getConnection();
$sql = "INSERT INTO `auth` (`username`, `password`, `email`, `phone`, `active`)
VALUES ('$user', '$pass', '$email', '$phone', '1');";
$error = false;
if ($conn->query($sql) === true) {
$error = false;
} else {
// echo "Error: " . $sql . "<br>" . $conn->error;
$error = $conn->error;
}
// $conn->close();
return $error;
}
}
<?php
include_once 'includes/Mic.class.php';
include_once 'includes/Database.class.php';
function load_template($name)
{
......@@ -15,31 +16,3 @@ function validate_credentials($username, $password)
return false;
}
}
function signup($user, $pass, $email, $phone)
{
$servername = "mysql.selfmade.ninja";
$username = "sibidharan";
$password = "xyjxo8-xefjat-gYnsif";
$dbname = "sibidharan_newdb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `auth` (`username`, `password`, `email`, `phone`, `active`)
VALUES ('$user', '$pass', '$email', '$phone', '1');";
$error = false;
if ($conn->query($sql) === true) {
$error = false;
} else {
// echo "Error: " . $sql . "<br>" . $conn->error;
$error = $conn->error;
}
$conn->close();
return $error;
}
......@@ -25,6 +25,8 @@ include 'libs/load.php';
$mic1 = new Mic("Roda"); //constructing the object
$mic2 = new Mic("HyperX"); //constructing the object
Mic::testFunction(); //no construction, no destruction.
testFunction();
$mic1->setLight("White");
$mic2->setLight("Green");
......@@ -36,5 +38,16 @@ print("\n".$mic1->getBrand());
print("\n".$mic2->getBrand());
print("Value of 10+12 is ".$mic1->add(10, 12));
print("This is mono font inside pre tag \n");
$conn = Database::getConnection();
$conn = Database::getConnection();
$conn = Database::getConnection();
$conn = Database::getConnection();
$conn = Database::getConnection();
$conn = Database::getConnection();
$conn = Database::getConnection();
?>
</pre>
\ No newline at end of file
</pre>
This is regular font.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment