Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. If it comes to validation and especially very thorough validation then i would recommend using objects, something along the lines of: <?php class FileUpload { protected $_validators = array(); public function addValidator(Validator $validator) { $this->_validators[] = $validator; } public function isValid($image) { if (!sizeof($this->_validators)) return true; if (is_file($image) && is_readable($image)) { foreach ($this->_validators as $validator) { if (!$validator->isValid($image)) { return false; } } return true; } return false; } } abstract class Validator { abstract public function isValid($input); } class ImageMimeTypeValidator extends Validator { protected $_imageMimeTypes; public function __construct($imageMimeTypes) { $this->_imageMimeTypes = $imageMimeTypes; } public function isValid($input) { $image = getimagesize($input); if (in_array($image['mime'], $this->_imageMimeTypes)) { return true; } return false; } } ... more validator .. ?> Use as: <?php $mimeTypes = array('image/jpeg', 'image/png', 'image/gif', ..); $fileUpload = new FileUpload(); $fileUpload->addValidator(new ImageMimeTypeValidator($mimeTypes)); if ($fileUpload->isValid($_FILE['upload']['tmp_name'])) { ..valid.. } ?>
  2. You mean something like this? <?php function aFunctionName($str, $webpages, $linksources) { for ($i = 0; $i < sizeof($webpages); $i++) { if (!strcmp($str, $webpage)) { return $linksources[$i]; } } return "Source Unknown"; } ?> btw, what is [webpagename] here? Maybe we can even simplify it further <?php if ( $row[3] == "http://[webpagename].com" ) {$linksource="BBC News"; ?>
  3. The error's mean that nor products() nor categories() is defined when you are calling them make sure you include the required files
  4. <?php $query = "SELECT timediff('2009-04-30 14:40:00',sysdate()) as timedifference"; $queryResult = mysql_query($query); list($timedifference) = mysql_fetch_array($queryResult, MYSQL_FETCH_NUM); ?>
  5. str_replace() takes 3 arguments not 2, thus: $last_item = str_replace('</br>', '', $arr[2]);
  6. However i don't think it should be a problem, but you can do this: <?php $urlencode = urlencode('!='); $urlencode = str_replace('%21', '!', $urlencode); // counter ?>
  7. Check: http://www.alistapart.com/articles/alternate/ or look for css switcher on google this option has an instant effect so you do not need to reload the page for it to work
  8. You need to use a .htaccess and have mod_rewrite enabled on your server
  9. you shouldn't use copy to move uploaded files from the temporary folder use move_uploaded_file() instead: http://be2.php.net/move_uploaded_file
  10. SELECT * FROM users WHERE name = 'john belushi' SELECT * FROM users WHERE name = 'JOHN BELUSHI' SELECT * FROM users WHERE name = 'JoHn bEluSHi' will always return the same result unless name has the attribute BINARY set. However it will not find John_Belushi use therefor the operator LIKE: SELECT * FROM users WHERE name LIKE 'john_belushi' Notice that _ here is a character pattern and will also match a space or any other as long as it is only exactly one character long more information can be found on the mysql documentation http://dev.mysql.com/doc/refman/6.0/en/string-comparison-functions.html#operator_like
  11. that's because when you use this: <?php $msg = ">> ". $row_act['activity'] ." - ". $row_act['insured']. " - " .$row_act['notes'] ."\r\n\n"; ?> you always overwrite the contents of $msg therefor use this: <?php $msg .= ">> ". $row_act['activity'] ." - ". $row_act['insured']. " - " .$row_act['notes'] ."\r\n\n"; ?> notice the . (dot) which concatenates strings
  12. 1) Correct read revraz comment for more on this 2) Generally yes but it depends on what you want to store 3) Until the browser is closed. Check for more information: http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime You can extend the lifetime of a cookie by altering it's settings through: http://be2.php.net/manual/en/function.session-set-cookie-params.php don't go with the information that mattal999 provides you cookies aren't the kind of resource you want to use as storage between requests as cookies are easy to create and modify sessions aren't really save either but they provide an extra layer of security
  13. Have you tried http://sourceforge.net/projects/html2fpdf or http://www.google.com/custom?domains=www.phpclasses.org&q=html+2+pdf&sa=Search&sitesearch=www.phpclasses.org&client=pub-2951707118576741&forid=1&channel=5742870948&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%23663399%3BGL%3A1%3BDIV%3A%23222222%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AA3C5CC%3BLBGC%3AA3C5CC%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BLH%3A50%3BLW%3A256%3BL%3Ahttp%3A%2F%2Ffiles.phpclasses.org%2Fgraphics%2Fgooglesearch.jpg%3BS%3Ahttp%3A%2F%2Fwww.phpclasses.org%2Fsearch.html%3BFORID%3A1%3B&hl=en
  14. Read this tutorial: http://www.phpfreaks.com/tutorial/basic-pagination It tells you how you can properly add pagination. This also works for galleries.
  15. Your config.php outputs content and therefor you get these errors, please post config.php for further debugging purposes
  16. <?php list($email) = mysql_fetch_row($sql); // first row list($level) = mysql_fetch_row($sql); // second row !== first row ?> use: <?php list($field1, $field2, ..) = mysql_fetch_assoc($sql); // or a simple $data = mysql_fetch_assoc($sql); $email = $data['email']; $user = $data['user']; .. ?> @revraz they have php.net for questions like: "What does list function do?"
  17. Instead of asking such questions try it! If it doesn't work then google it! If google refuses to tell you why? Then you can come here to ask us the reason why it doesn't work
  18. I wouldn't use scripts like right mouse disable especially not if you are going to output text as you immediatly are implying that we are thiefs. Besides the web is build to easily access information coop with it!
  19. <?php if (!empty($variable)) { ..add it to the e-mail.. } else { ..leave it.. } ?> P.S. Wouldn't it be better to separate the form into steps so you don't have to fill in and process those one million fields or create some sort of categories where the customer selects his category and get's a form specialized for his kind of problem.
  20. SET LastName = '$pieces[1]' would be not sufficient what if the last name consist out of more then one word? So i would suggest something similar like: <?php $firstname = array_shift($pieces); $lastname = implode(" ", $pieces); SET LastName = '$lastname' ?> Or try the option provided by PFMaBiSmAd
  21. <?php $handle = fopen('data.csv'); $lines = array(); while ($data = fgetcsv($handle)) { $oldcat = array("\"40\"", "\"52\"", "\"54\""); $newcat = array("100x", "1000x", "10000x"); $data[2] = str_replace($oldcat, $newcat, $data[2]); $lines[] = $data; } while ($line = each($lines)) { fputcsv($handle, $line); } fclose($handle); ?>
  22. What you are looking for is called pagination and here on phpfreaks we have a nice tutorial for you: http://www.phpfreaks.com/tutorial/basic-pagination
  23. First of all it would be better if you changed your username and password to something like john, ***** to display it here as we can access that.. Second what does that mysql_error() say?
×
×
  • 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.