Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. From Wikipedia: You are still using the PHP implementation for sessions (ie, the filesystem) also options like cache lifetime and such are missing. It's thus misleading.
  2. http://bugs.mysql.com/bug.php?id=34665 See the response by "[4 Mar 2008 11:24] Martin Hansson" A viable alternative is: CREATE TEMPORARY TABLE temp ENGINE=MEMORY ( SELECT foo FROM bar WHERE bat = baz ) UNION ( SELECT foo FROM bar WHERE bat = baz ) Then SELECT * FROM temp INTO OUTFILE ... DROP TABLE temp; EDIT: SELECT * FROM ( (SELECT foo FROM bar) UNION (SELECT baz FROM bat) ) as dummy INTO OUTFILE 'foo.csv' Works equally.
  3. Also the class name implies it's something it's not and your class actually violates SRP and the OCP principle. Since your class is responsible for both _SESSION and encryption of the data. Everytime the encryption of your session changes you have to go in the sessioncache class and change it, which is more prone to break existing code.
  4. Hoegaarden!!
  5. Belgium is the king of beers. Try a Duvel when you ever come to visit.
  6. Yeah try to explain that to a new PHP programmer. When you encourage him to look out for a PHP 5.3 book and ignore the PHP 6 ones as they are older than the previous... Or that they bought a book on PHP 6 and then ask me where they can download PHP 6 as they are unable to find it... and then the weird look they give you when you tell them: It's PHP 5.3.. partially.
  7. Since there is too much code to figure out where you are actually multiplying/adding the totals, here's some example code: echo calculate_total(array(215 => '', 213 => 1, 212 => 2, 214 => '')); function calculate_total(array $array) { $total = 0; foreach (array_filter($array) as $key => $value) { $total += $key * $value; } return $total; } The function cleans the array of unwanted values (empty). Then for each of the remaining values it will multiply the key with it's value and add it to the total.
  8. Or worse they are just being re-labeled. I found a book labeled PHP 5.3 that mentions ereg() whilst being deprecated, encourages to write SQL injectable queries, and does not mention lambda functions once or anything else of the new stuff. The author should be shot! (But kill the publisher first!) PS I can not be held responsible if either the author or the publisher should be harmed or killed. Will that hold in court?
  9. I've seen it be done on at least one occasion like: class ExampleFoo { private $bar; public function doStuffWithBar() {} private $bat; public function doStuffWithBat() {} }
  10. Here's the calculation you are looking for.
  11. Currently it's just a dummy but you can replace it with Smarty. You can use it in your <action-name>Action() methods. public function insertAction() { if ($this->request->offsetExists('MM_insert')) { /** process logic here **/ /** onError: $this->view->assign('error', $error); **/ /** onSuccess: header('Location: somewhere'); exit; **/ } $this->view->display('beheerder/insert.tpl'); }
  12. require 'BeheerderDAO.php'; class BeheerderController { public $view; public $request; public function __construct() { $this->dao = new BeheerderDAO; } public function insertAction() { /** your code here **/ } public function errorAction() { /** your error code here **/ } public function dispatch(array $input, $view) { $this->view = $view; $this->request = new ArrayObject($input); if (!isset($input['action'])) { return $this->errorAction(); } $methodName = strtolower($input['action']) . 'Action'; unset($input['action']); if (!method_exists($this, $methodName)) { return $this->errorAction(); } $this->$methodName(); } } /** * Is this file being called directly? ie http://domain/BeheerderController.php */ if (basename($_SERVER['REQUEST_FILENAME']) == basename(__FILE__)) { require 'MyTemplateView.php'; $_REQUEST = $_GET; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $_REQUEST = $_POST; } $controller = new BeheerderController; $controller->dispatch($_REQUEST, new MyTemplateView); } Of course you will need to abstract/move both the above if() statement and the dispatch() method if you want it to work in other cases as well. The DAO could look something like: class BeheerderDAO { public $conn; public function __construct() { require 'db-config.php'; $this->conn = mysql_connect($db['host'], $db['user'], $db['pass']); if ($this->conn === false) throw new RuntimeException('Failed to connect to the database server.'); if (mysql_select_db($db['name'], $this->conn) === false) throw new RuntimeException('Failed to select the specified database.'); } public function save($naam, $paswoord) { $sql = "INSERT INTO beheerder (naam, paswoord) VALUES ('%s', '%s')"; $frm = sprintf($sql, $naam, $paswoord); $res = mysql_query($sql, $this->conn); if ($res === false) throw new RuntimeException('Query failed. Beheerder has not been saved.' . "\r\n\r\n" . ' QUERY: ' . $frm . "\r\n\r\n" . ' ERROR: ' . mysql_error($this->conn)); return true; } } This setup is not ideal and violates a few principles (OCP, SRP, Encapsulation, comes to mind) but it should be simple enough for you to understand and pick up.
  13. Here are the files with all errors corrected. Your code is not nearly close to an OO MVC architecture. BeheerderForm.html <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="validateBeheerderPasw.js" type="text/javascript"></script> <link href="validateBeheerderPasw.css" rel="stylesheet" type="text/css"/> <title>BeheerderForm</title> </head> <body> <form action="BeheerderController.php" id="form1" name="form1" method="POST"> <div align="center"> <table width="200" border="1"> <tr> <td>naam</td> <td><label for="TFnaam"></label> <input type="text" name="TFnaam" id="TFnaam" /></td> </tr> <tr> <td>pasw</td> <td><label for="TFpasw1"></label> <input type="password" name="TFpasw1" id="TFpasw1" /></td> </tr> <tr> <td>herhaal pasw</td> <td><span id="spryconfirm1"> <label for="confirmpasw"></label> <input type="password" name="confirmpasw" id="confirmpasw" /> <span class="confirmRequiredMsg">A value is required.</span><span class="confirmInvalidMsg">The values don't match.</span></span></td> </tr> <tr> <td> </td> <td><input type="submit" name="Bvoegbeheertoe" id="Bvoegbeheertoe" value="Submit" /></td> </tr> </table> </div> <input type="hidden" name="MM_insert" value="form1" /> </form> <script type="text/javascript"> var spryconfirm1 = new Spry.Widget.ValidationConfirm("spryconfirm1", "TFpasw1"); </script> </body> </html> BeheerderController.php <?php require_once('Beheerder.php'); function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } class BeheerderController {/* this is doing what exactly? Sit and look pretty? */} if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $beheerder = new Beheerder(GetSQLValueString($_POST['TFnaam'], "text"),GetSQLValueString($_POST['confirmpasw'], "text")); // fatal error: Call to a member function setObj() on a non-object in C:\wamp\www\BeheerderController.php on line 41 // Notice: Undefined variable: beheerder in C:\wamp\www\BeheerderController.php on line 41 $beheerder->setObj($beheerder); } Beheerder.php <?php require_once('BeheerderDA.php'); class Beheerder { private $naam; private $paswoord; private $aB; function __construct($naam, $paswoord){ $this->naam = $naam; $this->paswoord = $paswoord; } function setObj ($aB){ $this->ab = $aB; } } $aBeheerderDA = new BeheerderDA (); $aBeheerderDA->saveBeheerder($aB); function getBeheerderNaam () { global $naam; return $naam; } function getBeheerderPaswoord() { global $paswoord; return $paswoord; } BeheerderDA.php <?php require_once('DBconnQualifield.php'); require_once('Beheerder.php'); class BeheerderDA { private $aB; private $naam; private $paswoord; public function __construct() {} public function saveBeheerder ($aB){ $this->aB = $aB; } } $naam = getBeheerderNaam (); $paswoord = getBeheerderPaswoord (); if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 1 $insertSQL = sprintf("INSERT INTO beheerder (naam, paswoord) VALUES ('%s', '%s')",$naam,$paswoord); mysql_select_db($database_DBconnQualifield, $DBconnQualifield); $Result1 = mysql_query($insertSQL, $DBconnQualifield) or die(mysql_error()); } mysql_select_db($database_DBconnQualifield, $DBconnQualifield); $query_RSvoegbeheerdertoe = "SELECT * FROM beheerder"; $RSvoegbeheerdertoe = mysql_query($query_RSvoegbeheerdertoe, $DBconnQualifield) or die(mysql_error()); $row_RSvoegbeheerdertoe = mysql_fetch_assoc($RSvoegbeheerdertoe); $totalRows_RSvoegbeheerdertoe = mysql_num_rows($RSvoegbeheerdertoe);
  14. You may want to edit ( icon) your post (or ask a mod) and remove your e-mail address otherwise spam bots will be glad to fill your inbox for you!
  15. Sorry, we don't do that. We'll be glad to help, just post your question on the forum, give everyone a chance to answer.
  16. Did you try mine?
  17. No ALWAYS use double quotes for attribute values. Worst case you could still use this: echo <<<HTML <table border="0" style="height:100%;width:570px;border:solid 1px #BBB"> HTML;
  18. Don't use PHP to echo out HTML. Use PHP only for PHP specific parts (echo a variable, calculate a value, if/else, ..). <?php /* Copyright (C) 2009 Murad <Murawd> Josh L. <Josho192837> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ // Must rewrite ?> <fieldset> <legend> Manage User </legend> <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> <tr class="navtitle" style="height:25px"> <th style="width:auto">Mute A User From Posting</th> </tr> <tr> <td align="center" class="tdbox"> Search for the profile name you wish to mute. </td> </tr> <tr> <td align="center"> <form method="post" action=''> <input type="text" name="name" /> <input type="submit" name="search" value="Search" /> </form> </td> </tr> <tr style="height:25px"> <td class="tdbox"> <span style="float:left"> <a href="?cype=admin">Back To Administration Control Panel</a> </span> <span style="float:right"> <a href="?cype=admin&page=unmuteuser">Unmute User</a> </span> </td> </tr> </table> </fieldset>
  19. Shitty numbers.. Am I the only one who thinks that study smells..?
  20. This will work if you only have one DB connection. If you work with more than one DB server you should use something like: $userData = array_map(function($value) use (&$db2) { return mysql_real_escape_string($value, $db2); }, $_POST); $db2 being the database connection you want to use.
  21. http://code.google.com/p/zen-coding/wiki/ZenHTMLSelectorsEn http://code.google.com/p/zen-coding/wiki/ZenHTMLElementsEn Complete explanation of what you want to achieve. Going wild: html[lang="nl" class="foo"]:5>body>div[id="wrapper"]>(div[class="left"]>div*3)+(div[class="middle"]>div*3)+(div[class="right"]>div*3)
  22. I wrote this. Assuming both times are on the same day. try { $t1 = new Time($argv[1]); $t2 = new Time($argv[2]); echo $t1->diff($t2); } catch (Exception $e) { echo $e->getMessage(); } class Time { private $seconds; public function __construct($time) { if (!self::valid($time)) throw new InvalidArgumentException('Invalid time. Type: ' . gettype($time)); $this->seconds = $this->_toSeconds($time); } public static function valid($time) { if (!is_string($time)) return false; return preg_match('~^(\d|0\d|1\d|2[0-3])\d|[0-5]\d)$~', $time); } public function diff(Time $t) { $t1 = $this->toSeconds(); $t2 = $t->toSeconds(); $diff = ($t1 - $t2); if ($diff === 0) return '00:00'; return $diff < 0 ? $this->_toString($t2 - $t1) : $this->_toString($diff); } private function _toSeconds($time) { if (!self::valid($time)) throw new InvalidArgumentException('Invalid time. Type: ' . gettype($time)); sscanf($time, '%d:%d', $h1, $m1); return ($h1 * 3600) + ($m1 * 60); } public function toSeconds() { return $this->seconds; } private function _toString($seconds) { if (!is_int($seconds)) return false; return floor($seconds / 3600) . ':' . floor(($seconds % 3600) / 60); } } >php time.php 13:35 17:35 4:00 >php time.php 21:35 05:35 16:00 # reverses the arguments
  23. ignace

    CSV

    See: Replication
  24. Go for 18k. If it's true that you are hard-working, and committed, plus you work in your spare time your even worth more than that.
  25. Well you never gonna get a raise from 14 to 25k unless you are a business critical asset. Try 16k or if you are bold enough, try 18
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.