Jump to content

next

Members
  • Posts

    140
  • Joined

  • Last visited

Everything posted by next

  1. Procedure: DELIMITER $$ DROP PROCEDURE IF EXISTS `test`.`discounted_price` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `discounted_price`(price NUMERIC(8, 2), OUT discount_price NUMERIC(8, 2)) BEGIN IF(price > 500) THEN SET discount_price = price * 0.8; ELSEIF(price > 100) THEN SET discount_price = price * 0.9; ELSE SET DISCOUNT_price = price; END IF; END $$ DELIMITER ; call: CALL discounted_price(300, @new_price); SELECT @new_price; this should return price after discount, but for some reason returns 'null'. How do i fix this? Also what does '@' do? Thanks.
  2. Took me while but i was able to figure it out.
  3. How can i rename few columns? i tried USE phpsite_1; ALTER TABLE entry CHANGE contribution_id, contribution_body entry_id INT, entry_body TEXT(1000); but it doesn't work. Any suggestions? Thanks.
  4. Please recommend a definite must read for PHP+MySQL. Content should include PHP5 OOP, advanced MySQL technics (like procedures, joins, proper DB development), security and most importantly good examples. I was reading "Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition" which is a really great book in my opinion, but unfortunately i'm unable to proceed thanks to PDO bug under windows, and all attempts to fix this bug where unsuccessful. Thanks.
  5. I'm trying to figure out how to display only first 100 characters followed by "... read full article", but can't seem to get it. Please help. Thanks.
  6. I use server on a stick, they are only up to 5.2.5, i tried Server2Go which has 5.2.6 on it, but i couldn't get that damn server to work. I really hope that they will fix this problem, because this is an excellent book(By Christian Darie btw, it's his blog that you linked to in your first post.). Well i tried to work around it, but i'm a NOonb to php and was unsuccessful. I guess i'll read something else for now. Thanks.
  7. Nah, it gives me another error: ERRNO: 256 TEXT: could not find driver LOCATION: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php, line: 26, at July 1, 2008, 10:51 am Showing backtrace: trigger_error("could not find driver", "256")# line 26, file: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php DatabaseHandler.GetHandler()# line 63, file: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php DatabaseHandler.GetAll("CALL catalog_get_departments_list()")# line 7, file: E:\PortableApps\WOS\www\tshirtshop\business\catalog.php Catalog.GetDepartments()# line 14, file: E:\PortableApps\WOS\www\tshirtshop\presentation\departments_list.php DepartmentsList.init()# line 10, file: E:\PortableApps\WOS\www\tshirtshop\presentation\smarty_plugins\function.load_presentation_object.php smarty_function_load_presentation_object(Array[2], Object: Application)# line 5, file: E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%A5^A5A^A5A1C73D%%departments_list.tpl.php include("E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%A5...")# line 1871, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php Smarty._smarty_include(Array[2])# line 40, file: E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%41^412^412F4E3D%%store_front.tpl.php include("E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%41...")# line 1258, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php Smarty.fetch("store_front.tpl", null, null, true)# line 1108, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php Smarty.display("store_front.tpl")# line 13, file: E:\PortableApps\WOS\www\tshirtshop\index.php It looks like this dll is not recognized.
  8. I'm following a book on creating a Shopping Cart and stumbled upon a problem. I researched it online and it seems that this is a bug with php 5.2, i was unsuccessful at finding a remedy though. Does anyone know how to fix this? My error: Code: <?php //generic data access functionality class DatabaseHandler { //hold an instance of the PDO class private static $_mHandler; //private constructor to prevent direct creation of object private function __construct() { } //return an initialized database handler private static function GetHandler() { //create DB connection if not yet connected. if(!isset(self::$_mHandler)) { //execute code catching potential exceptions try { //create a new PDO class instance self::$_mHandler = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY)); self::$_mHandler->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); //configure PDO to throw exceptions self::$_mHandler -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { //close the database handler and trigger an error self::Close(); trigger_error($e -> getMessage(), E_USER_ERROR); } } //return database handler return self::$_mHandler; } //Clear the PDO class instance public static function Close() { self::$_mHandler = null; } //wrapper method for PDOStatement::execute() public static function Execute($sqlQuery, $params = null) { //try to execute an SQL query or a stored procedure try { //get DB handler $database_handler = self::GetHandler(); //Prepare the query for execution $statement_handler = $database_handler -> prepare($sqlQuery); //execute query $statement_handler -> execute($params); } catch (PDOException $e){ //close the DB handler and trigger an error self::Close(); trigger_error($e -> getMessage(), E_USER_ERROR); } } //wrapper method for PDOStatement::fetchAll() public static function GetAll($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC) { //initialize the return value to null $result = null; //try to execute an SQL query or a stored procedure try { //get DB handler $database_handler = self::GetHandler(); //prepare the the query $statement_handler = $database_handler -> prepare($sqlQuery); //execute query $statement_handler -> execute($params); //fetch result $result = $statement_handler -> fetchAll($fetchStyle); } //trigger an error if an exception was thrown when executing the SQL query catch (PDOException $e){ self::Close(); trigger_error($e -> getMessage(), E_USER_ERROR); } return $result; } public static function GetRow($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC) { //initialize the return value to null $result = null; try { $database_handler = self::GetHandler(); $statement_handler = $database_handler -> prepare($sqlQuery); $statement_handler -> execute($params); $result = $statement_handler -> fetch($fetchStyle); } catch(PDOException $e) { self::Close(); trigger_error($e -> getMessage(), E_USER_ERROR); } return $result; } //return the first column value from a row public static function GetOne($sqlQuery, $params = null) { $result = null; try { $database_handler = self::GetHandler(); $statement_handler = $database_handler -> prepare($sqlQuery); $statement_handler -> execute($params); $result = $statement_handler -> fetch(PDO::FETCH_NUM); //save the first value of the result set to $result $result = $result[0]; } catch(PDOException $e) { self::Close(); trigger_error($e -> getMessage(), E_USER_ERROR); } return $result; } } ?>
  9. Oops, never mind, problem solved
  10. i'm following a tutorial to create a gallery and it uses createThumbnail() in it's code, as far as i understand from authors explanation it's a GD function, but i keep getting an error: What's wrong here? Code: <?php require("config.php"); include("header.php"); if($_POST['submitted']) { $albumName = $_POST['album']; $description = $_POST['description']; $imageName = $_FILES['image']['name']; $tmpName = $_FILES['image']['tmp_name']; $ext = strrchr($imageName, "."); $newName = md5(mt_rand()).$ext; $imgPath = ALBUM_IMG_DIR . $newName; //resize $result = createThumbnail($tmpName, $imgPath, THUMBNAIL_WIDTH); if($result == false) { echo "error during upload."; exit(); } if(!get_magic_quotes_gpc()) { $albumName = addslashes($albumName); $description = addslashes($description); } $query = "INSERT INTO tbl_album(al_name, al_description, al_image, al_date) VALUES('$albumName', '$description', '$newName', NOW())"; mysql_query($query) or die('Error, add album failed : ' . mysql_error()); header("location: http://localhost/gallery/list_album.php"); exit(); } ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <ul id="form"> <li><label for="album">Album Name:</label><input type="text" id="album" name="album" maxlength="64" /></li> <li><label for="description">Description:</label><textarea rows="5" cols="15" name="description"></textarea></li> <li> <label for="image">Image:</label> <input type="file" id="image" name="image" /> </li> <li><input type="submit" name="submit" value="Add Album" /><input type="submit" name="cancel" value="cancel" /></li> <input type="hidden" name="submitted" value="true" /> </ul> </form> <?php include("footer.php"); ?> here's is the exact line: $result = createThumbnail($tmpName, $imgPath, THUMBNAIL_WIDTH); THUMBNAIL_WIDTH equals to 60. Thanks in advance
  11. Woooooow, it's not FF, it's IE who has it wrong. Look at your line-height property, 25px? That's way too much.
  12. i tried while($file = readdir($dir_handle)) { if(is_file($file)) { $fileCount++; echo "$fileCount - $file<br />"; } } but it returns a null result ??? . I pretty much count images, i could use InStr to check, but wondering why is is_file breaking my result. Any ideas?
  13. $site_root = $_SERVER['DOCUMENT_ROOT']; $images_dir = $site_root . "/gallery/images"; $dir_handle = opendir($images_dir); while($file = readdir($dir_handle)) { $fileCount++; echo "$fileCount - $file<br />"; } why are the first 2 listed items are dots??? I have 11 files in a directory, count returns 13: and is there a better way to count files? Thanks.
  14. Yeah, it doesn't have to be int, declare it as public type.
  15. next

    PHP help

    You need to put your code inside tags for readability. What's not working? Where is your form? What do the error messages say?
  16. if($dbpass) { $_SESSION['sessionuser'] = $dbuser; $_SESSION['sessiongallery'] = $dbgallery; $_SESSION['sessionpassword'] = $dbpass; echo "<meta http-equiv=\"refresh\" content=\"0;URL=gallery/index.php\">"; } else session_destroy(); echo "<meta http-equiv=\"refresh\" content=\"0;URL=wrong_id.php\">"; i think you need to specify block for "else", i mean: else { session_destroy(); echo "<meta http-equiv=\"refresh\" content=\"0;URL=wrong_id.php\">"; } Not tested.
  17. '@' suppresses error/warning messages. $queryvars's default value is blank, meaning that parameter doesn't have to be specified when you call the function.
  18. I really like having my MySql + PHP + Apache on my USB stick and currently run WOS, my problem is that WOS is not that great. I once had i think WAMP installed at home and i was able to view all installed PHP extensions and had few not that important but sometimes useful features, WOS doesn't have that. What do you guys use and why? Thanks.
  19. Outstanding!!! It's working. Thanks a lot !!!
  20. Thanks!!! I can see the image, but it's not generating the security code , how do i fix this? Thanks.
  21. I just found a tutorial on capcha and can't figure out how to get it to work: form.php <?php session_start(); if(isset($_POST['submit'])) { $secCode = isset($_POST["secCode"]) ? strtolower($_POST["secCode"]): ""; if($secCode == $_SESSION["securityCode"]) { echo "<p>The result code was valid!</p>"; unset($_SESSION["securityCode"]); $result = true; } else { echo "<p>Invalid code, try again.</p>"; $result = false; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title><?php echo $site_name; ?></title> <style type="text/css">img {margin: 0 10px;}</style> <script type="text/javascript" src="javascript.js"></script> </head> <body> <form action="<?php $PHP_SELF ;?>" method="post"> <label for="securityCode">Security Code <input type="text" name="securityCode" size="10" /><img src="securityCode.php" alt="security" border="1"></label> <input type="submit" name="submit" value="submit" /> </form> </body> </html> securityCode.php <?php $width = 120; $height = 40; $baseList = '0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //generate image $image = @imagecreate($width, $height) or die("Unable to initialize GD."); for($i = 0; $i < 10; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), imagecolorallocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255))); } //add random characters to image for($i = 0, $x = 0; $i < $length; $i++) { $actChar = substr($baseList, mt_rand(0, strlen($baseList)-1), 1); $x += 10 + mt_rand(0, 10); imagechar($image, mt_rand(3, 5), $x, mt_rand(5, 20), $actChar, imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155))); $code .= strtolower($actChar); } header("Content-Type: image/jpeg"); imagejped($image); imagedestroy($image); $_SESSION["securityCode"] = $code; ?> My problem is that it never shows the actual image, i see only alternative text(img alt="security"). I though that maybe my GD is disabled but here's what my phpinfo() shows: How do i get it to work? Thanks in advance.
  22. I'm curious because since I'm new to PHP and web security maybe I'm missing some important details, but to be honest i don't see how additional page makes my site more secure. Thanks for your replies.
  23. I checked out few tutorials recently about logins and registration. I'm confused, authors in every tutorial were building separate login pages for users and admins, same goes for logout pages. Why would i want 4 pages(2 logins and 2 logouts)? Why not just use conditional statements instead?
  24. Is there a plugin that will help me do this? So far i saw only readonly functions. Thanks.
×
×
  • 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.