Example #1
0
<?php 
session_start();
include "./myclasses.php";
//load queries
$q = new Queries();
//Get connection to the DB
$connObj = new MySQLConn();
$connObj->getConnection();
if (isset($_GET['userId'])) {
    /*Handling the case when the user need to be activated
     */
    $id = $_GET['userId'];
    $query_str = sprintf($q->updActivateUser(), $id);
    //echo "This is the formatted string:<br>";
    //echo $query_str."<br>";
    $connObj->executeQuery($query_str);
    echo "<h1>Account activated!</h1><hr>";
    echo "Your account has been activated!<br>";
    echo "Please go to this <a href='http://localhost/login.php'>link</a> to login!";
} else {
    $userObj = new User();
    $userObj->setFirstName($_POST["firstname"]);
    $userObj->setLastName($_POST["lastname"]);
    $userObj->setEmail($_POST["email"]);
    $userObj->setPassword($_POST["password"]);
    $userObj->setUserActivated(0);
    //by default
    //echo "The name you sent is:  ". $userObj->getFirstName() . "!!!";
    /*Validate if the user exists.  If it does, then just check if its already activated by checking this field in the DB, if not
     *then resend an activation email to the email of the user and redirect the user to a page where it tells that an email has been sent to
Example #2
0
<?php

import("data.MySQLConn");
import("lib.Logger");
import("exceptions.DatabaseException");
/**********************************************/
/* - create database connection               */
/**********************************************/
//attempt to create connection to database if necessary
try {
    $retval = MySQLConn::connect('sg_problem_2', null, 'root', 'c00kie');
    if (!$retval) {
        Logger::write(Logger::FATAL, "Error - database failed to connect.");
    }
} catch (DatabaseException $e) {
    Logger::write(Logger::ERROR, "Error connecting to database.", $e);
}
//end CATCH
Example #3
0
 public static function commit()
 {
     MySQLConn::$_transaction = false;
     if (MySQLConn::status()) {
         MySQLConn::$_conn->commit();
     } else {
         throw new DatabaseException(__METHOD__ . "::Database not connected!");
     }
 }
Example #4
0
<?php

session_start();
include "./myclasses.php";
//load queries
$q = new Queries();
//Get connection to the DB
$connObj = new MySQLConn();
$connObj->getConnection();
if (isset($_SESSION['username'])) {
    //3 scenarios: upload the image, view images and delete image
    //First
    if ($_GET['act'] == "uimg") {
        //TODO: put more restrictions like file size, type of file, etc
        $filename = $connObj->escapeMe($_FILES['imgfile']['name']);
        $fileSize = $_FILES["imgfile"]["size"];
        $fileObj = $_FILES["imgfile"]["tmp_name"];
        $userId = $_SESSION["userId"];
        $sql = sprintf($q->insInsertImg(), $userId, $fileObj, $filename, $fileSize);
        $connObj->executeQuery($sql);
        echo "<h1>Your image has been saved!!!</h1>";
        echo "<hr><h3>Please go to the main <a href=http://localhost/dashboard.php>menu</a> for more options.</h3>";
    }
    //Second
    if ($_GET['act'] == "viewimg") {
        $userId = $_SESSION["userId"];
        $connObj->escapeMe($userId);
        $sql = sprintf($q->getImgByUserId(), $userId);
        $connObj->executeQuery($sql);
        $result = $connObj->fetchArray();
        foreach ($result as $img) {