protected function cleanAndPost() { for ($n = 0; $n < count($this->message_information); $n++) { //clean left and white white space, escape the string for the Database $this->message_information[$n] = Sanitize::prepForDatabase(Sanitize::clearWhiteSpaceLR($this->message_information[$n])); } $d = new Database(); $d->open('hacker_blog'); //check for duplicates $chx = $d->q("SELECT * FROM user_messages WHERE user_messages.message = '{$this->message_information[2]}'"); if ($chx && $d->numrows() <= 0) { // id in the messages field is for the user's uid or user_id, depending on how you are moving forward with your code $s = $d->q("INSERT into user_messages\n\t\t\t\t \t\t(user_message_id,first_name,last_name,id,message,type,added_on) VALUES\n\t\t\t\t\t\t(NULL,'{$this->message_information[0]}','{$this->message_information[1]}',NULL,'{$this->message_information[2]}','{$this->type}',now())"); if ($s) { //echo 'made it through gauntlet. Added info into Database.'; $this->passed = true; } else { $this->passed = false; } } else { //echo 'You have already made a comment like this.'; $this->passed = false; } $d->close(); //print_r($this->message_information); }
public function getMainNavigation() { $d = new Database(); $d->open('hacker_blog'); $sql = "SELECT * FROM navigation "; if ($this->type == 'private') { $sql .= " WHERE public = 0 "; } else { $sql .= " WHERE private = 1 "; } $s = $d->q($sql); if ($s && $d->numrows() >= 1) { $arr = array(); while ($r = $d->mfa()) { //print_r($r); array_push($arr, $r); } $this->messages = array("success" => "Found Navigation"); $this->current = $arr; return $arr; $d->close(); } else { $this->messages = array("error" => "Could not Find Navigation"); $d->close(); return false; } }
public function getPage($id = null) { if (is_int($id)) { $this->page_id = $id; } $d = new Database(); $d->open('hacker_blog'); $s = $d->q("SELECT * FROM pages WHERE id = '{$this->page_id}'"); if ($s && $d->numrows() >= 1) { return $d->mfa(); $d->close(); } else { return false; } }
public function getMainNavigation() { $d = new Database(); $d->open('hacker_blog'); $s = $d->q("SELECT * FROM navigation"); if ($s) { $r = $d->mfa(); $this->messages = array("success" => "Found Navigation"); $d->close(); return $r; } else { $this->messages = array("error" => "Could not Find Navigation"); $d->close(); return false; } }
public function createBlogPost($title = null, $body = null) { $this->title = (string) $title; $this->body = (string) $body; //$this->title = Sanitize::sanitize_string($this->title); //$this->body = Sanitize::sanitize_string($this->body); // add database method to push into Database // mysql_real_escape_string (php.net for use examples) $d = new Database(); $d->open('hacker_blog'); //$d = new Database(); //$d->setDB('hacker_blog'); $s = $d->q("INSERT INTO blog_entries (blog_id,user_id,blog_title,blog_created_at,blog_updated_at,blog_body) VALUES (NULL,1,'{$this->title}',now(),now(),'{$this->body}');"); $d->close(); if ($s) { return true; } else { return false; } }
public function readBlogPost($start = 0, $end = 5, $post_id = null, $order = null) { $d = new Database(); $d->open('hacker_blog'); $sql = "SELECT * FROM blog_entries "; if (is_int($post_id)) { $sql .= " WHERE blog_id = '{$post_id}' "; } if (is_string($order)) { $sql .= " ORDER BY {$order} "; } $sql .= " LIMIT {$start}, {$end}"; // $s = $d->q($sql); if ($s && $d->numrows() >= 1) { $posts = array(); while ($r = $d->mfa()) { array_push($posts, $r); } return $posts; } else { return false; } }
<?php // // this is more or less a list of examples of how to get anything out of the database // may be eventually merged into receipt... // // Stuart Feldt 2010/11/17 // require_once('../backbone/Database.php'); require_once('../backbone/capstone.db'); $d = new Database($user, $pass, $dbname, $host, 'mysql'); $total = 0; $q = "SELECT * FROM statuses"; $statuses = $d->q($q); foreach($statuses as $status) { print $status['statusid']." - ".$status['status']."<br />"; } $q = "SELECT * FROM items"; $menu_items = $d->q($q); foreach($menu_items as $menu_item) { print $menu_item['name']." - ".$menu_item['categoryid']."<br/>"; $sql = "SELECT * FROM ingredients WHERE ingredientid IN (SELECT ingredientid FROM items_have_ingredients WHERE itemid='".$menu_item['itemid']."');"; $item_ingredients = $d->q($sql); foreach($item_ingredients as $ingredient) { print "Ingredient - ".$ingredient['name']."</br />"; }
set_include_path('backbone:components:content:scripts:styles:images'); require_once('Page.php'); require_once('Template.php'); require_once('Database.php'); require_once('capstone.db'); $table_data; $page = new Page(0, "OrderUp - All Categories"); $d = new Database($user, $pass, $dbname, $host, 'mysql'); $tmpl = new Template(); $orders = $d->q("SELECT * FROM orders"); foreach($orders as $order) { $total = 0; $table_data = $table_data."<td>".$order['orderid']."</td>"; $table_data = $table_data."<td>".$order['tableid']."</td>"; $table_data = $order['isSubmitted']==1 ? $table_data."<td>Yes</td>" : $table_data."<td>No</td>"; $table_data = $table_data."<td>".$order['time']."</td><td>"; $table_data = $table_data.$order['specialComment']."</td>"; //get user id's at table $userq = "SELECT * FROM users WHERE userid = ".$order['userid']; $user = $d->q($userq);
<?php require_once '../blog/includes/session.php'; require_once '../blog/classes/clsDatabase.php'; require_once '../blog/classes/clsSanitize.php'; if ($_POST['login']) { //print_r($_POST); // sanitize $login = Sanitize::clearWhiteSpaceLR($_POST['login']); //$password = Sanitize::clearWhiteSpaceLR($_POST['password']); $password = strtolower(Sanitize::clearWhiteSpaceLR($_POST['password'])); //echo $login.' '.$password; // test if in Database as well $d = new Database(); $d->open('hacker_blog'); $s = $d->q("SELECT * FROM user WHERE user.username = '******' AND user.password = sha1('{$password}') LIMIT 0,1"); if ($s && $d->numrows() > 0) { //mysql fetch assoc $info = $d->mfa(); //print_r($info); //$info = associative array $_SESSION['loggedin'] = true; // concat first and last name $name = $info['user_first_name'] . ' ' . $info['user_last_name']; //echo "NAME: $name"; $_SESSION['loggedin'] = true; $_SESSION['user_full_name'] = $name; $_SESSION['user_quick_name'] = $info['user_first_name']; $_SESSION['user_id'] = $info['id']; //echo '<a href="/week_eight/secret_loggedin_area.php">Manual Override</a>'; header("Location: /week_eight/secret_loggedin_area.php");
<?php // here is a helpful controller file // we can use this to help us create a much better experience for ourselves! $basic = "Hero"; $data = new Database(); $data->open('phpclass'); $user_data = $data->q("SELECT * FROM users"); //Resource ID $resource = $data->getResource(); $r = $data->mfa($user_data); $data->close(); // used to call a function and get a result, yeah. //print_r($r);
<?php // here is a helpful controller file // we can use this to help us create a much better experience for ourselves! $basic = "Hero"; $data = new Database(); $data->open('phpclass'); $s = $data->q("SELECT * FROM users"); $r = $data->mfa(); $data->close(); // used to call a function and get a result, yeah. print_r($r);
<?php set_include_path('backbone:components:content:scripts:styles:images'); require_once('Page.php'); require_once('Template.php'); require_once('Database.php'); require_once('capstone.db'); $page = new Page(0, "OrderUp - All Categories"); $db = new Database($user, $pass, $dbname, $host, 'mysql'); $tmpl = new Template(); $sql = "SELECT * FROM categories ORDER BY number ASC"; $tmpl->cats = $db->q($sql); $page->run(); $html = $tmpl->build('categories.html'); //$css = $tmpl->build('categories.css'); //$js = $tmpl->build('categories.js'); $appContent = array( 'html' => $html, 'css' => $css, 'js' => $js ); print $page->build($appContent); ?>