Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Please post your code. If the query from Ken2k7 didn't work then that means that a) you have no records with live = 1 or b) there is something wrong with your code. I presume the latter.
  2. 1) <input type="checkbox" name="delete" value="1" /> <?php if (sizeof($_POST) && isset($_POST['delete']) && $_POST['delete'] === 1) { ..delete entry.. } 2) Use the hidden value technique <input type="hidden" name="validate" value="no" /> <input type="checkbox" name="validate" value="yes" /> when checked will say yes if not will say no
  3. Ok i'm going to give you the full lowdown on this one. First you need to make some sort of requirements list as you are creating it for yourself you can keep it to functional requirements a functional requirement may be: - An article cannot be published until it is reviewed and approved by an editor - or a product cannot be purchased until an email address is given Once you have these functional requirements for your iTunes store you separate your project into two groups, both teams will adhere to the requirements one team called the webdesign team will create a flowchart (http://www.backe.com/images/web.gif) This identifies all the pages within your website then for each page you create a so-called wireframe which documents the structure of the page (http://www.gliffy.com/examples/wireframes/images/wireframe_example.png) After this is done you create a template using Photoshop or some other image editing software. The design team is done at this point. The second team the webdevelopment team will based on the requirements build an erd (http://www.cbe.wwu.edu/misclasses/mis431s05/431code%5CSCR-SO-ERD.gif) and a class diagram (http://www.codeproject.com/KB/library/WinSNMPWrapper/class_diagram.png) maybe even a state diagram or a data flow diagram. With all functionality documented you can now write your very first lines of code after all classes on the class diagram have been implemented and all templates have been turned into functional html pages you proceed to the next phase: Quality Assurance This is where you test your code by using Selenium (http://seleniumhq.org/ - webdesign) and Unit Testing (http://en.wikipedia.org/wiki/Unit_testing - webdevelopment)
  4. Yeah that will work. Another solution would be using an object oriented approach: <?php class Internet extends Category { protected $_postKey = 'internet'; protected $_categoryName = 'Internet'; .. } $budget = new Budget(); $budget->addCategory(new Internet()); /** * A budget has categories when the form is send it loops over the categories and looks * if one exists in the provided array ($_POST) if it does it uses that value to update the budgets table */ if (sizeof($_POST)) { $budget->updateTable($_POST); } .. updateTable($array) { foreach ($this->_categories as $category) { if (isset($array[$category->getPostKey()]) && !empty($array[$category->getPostKey()])) { .. UPDATE budgets SET amount = $array[$category->getPostKey()] WHERE sub_category = $category->getCategoryName() ?> Personally i would recommend your code if it works best for you. My code is based upon the Zend Framework Zend_Form and Zend_Db packages where each form field is represented by a class with some proper modification you can make it work in such a way that when you want to add a category all that is needed is a new class and 1 line of code
  5. Interesting, finally a challenge You have another problem everytime you submit the form you submit every field wether or not it needs to be updated which means a serious amount of processing I would suggest using jQuery or something and a few plugins so that you can dubbleclick on a value in the table so it turns into an editable textarea and allows you to edit it, the plugin will then submit the new value to a php script and execute a more precise query, like: UPDATE budgets SET amount = $amount WHERE sub_category = 'Internet'; Or if you had modifed the value of electricity the query would have been: UPDATE budgets SET amount = $amount WHERE sub_category = 'Electricity';
  6. <?php echo '<div class="error-msg">Message not sent. Please make sure you\'re not running this on localhost and also that you are allowed to run mail() function from your webserver</div>'; ?> You could eliminate mail() entirely so that you can send your e-mails even from localhost: http://chimit.mirrors.phpclasses.org/blog/package/14/post/2-Sending-email-using-SMTP-servers-of-Gmail-Hotmail-or-Yahoo-with-PHP.html
  7. But I must include this script in every other page because some of the options on the other pages may be viewed by A, B and not by C for exemple. Then you are no longer talking about authentication (logging in/logging out) but authorization have a look at access control http://en.wikipedia.org/wiki/Role-based_access_control. You need to start your session before you can add information to it, start your session by typing session_start(); on the top of your page before you have any output. I would also strongly advice creating some functions like authenticate($user, $pass), is_authenticated() and is_authorized($resource, $privilege) as these functionality will be most likely be used throughout your application
  8. ignace

    Images

    Then only use the name LIKE '%%%s%%' part htmlentities is a security measure against sql injection mysql_real_escape_string() is even better but i don't use mysql as a database, the next line in the code is a formatted string or if you use mysqli a prepared statement the double %% represent a % and %s represents a string which means that whatever is passed is converted to a string read up on sprintf() on php.net http://be.php.net/sprintf The function searchResult() is only to make your code more clearer and more easy to read it does this by encapsulating your html code inside a function which gets the required information passed along. This way you can more easily use it again somewhere else in your application.
  9. Please post the php code if any
  10. Why not use cURL? cURL allows you to pass authentication data along.
  11. Well the big challenge here is knowing how you can create an array from normal fields. To create an array simply add [] to the name field identifier and add it for every field that is part of the array, like so: <input type="checkbox" name="teams[]" id="teams" value="1" /> <input type="checkbox" name="teams[]" id="teams" value="2" /> <input type="checkbox" name="teams[]" id="teams" value="3" /> <input type="checkbox" name="teams[]" id="teams" value="4" /> <input type="checkbox" name="teams[]" id="teams" value="5" /> In php you threat it like a normal array: <?php print_r($_POST['teams']); ?>
  12. ignace

    Images

    1) use the proper code tags when posting code 2) Read up on SQL Injection as you are vulnerable http://en.wikipedia.org/wiki/SQL_injection <?php $search = htmlentities($_GET['search']); $query = sprintf("SELECT * FROM prints WHERE id = '%s' OR name LIKE '%%%s%%' OR manufacturer LIKE '%%%s%%'", $search, $search, $search); $queryResult = mysql_query($query); while ($row = mysql_fetch_assoc($queryResult)) { echo searchResult($row); } function searchResult($row) { ..html markup code for a search result.. } ?>
  13. 1) Wow, hard math.. 2) Shouldn't this be posted under PHP Math?
  14. <?php function strsum($str) { if (!is_numeric($str)) return 0; $str = strval($str); for ($i = 0; $i < strlen($str); $i++) { $sum += intval($str[$i]); } return $sum; } print strsum(256); // 13 ?>
  15. 1) cURL most likely 2) The username and password of your computer which you use to login
  16. 1) the cookie's lifetime is 0 this means that when you close the browser it get's deleted 2) depends on the information stored 3) the default session is not 1440 but 0 which again means that when you close the browser you are also logged off to extend this see http://be2.php.net/manual/en/function.session-set-cookie-params.php What you are referring to is the garbage collection lifetime which is 1440 by default this means that after 1440 seconds the session will be deleted from your server
  17. You can not limit the amount of rss feeds read if using xml_*() functions. If you want to limit the amount of rss feeds read you need to first read the rss then loop over the entries and after each loop see if the limit has been reached. <?php // read the file: $rssFeed = file_get_contents('../rss/feed.xml'); $xml = new SimpleXmlElement($rssFeed); $counter = 0; $limit = 10; foreach ($xml as ..) .. $counter++; if ($counter === $limit) break; } ?> However there must be a way to only read the first x records instead of each and every entry
  18. please post your code to make things absolutly clear
  19. function processAjax() { var ajax = new XMLHttpRequest(); ..validation calls.. ..something.. ajax.call('form-process.php', 'get'); ..again something.. return false; // cancel submission as ajax already deals with it } <form onsubmit="return processAjax()" .. I would however strongly advice using a framework as you do not want to write out all the solutions to all the browser difference problems with javascript. Use jQuery for example.
  20. You can use javascript or php for this. With php you would just redirect the user to another page basically you would assume 5 seconds before redirecting to the new page depending on the current system load if the system load is heavy you can increase that number. page #1 header('Location: page2.php'); page #2 function waitTime() { $baseWaitTime = 5; //secs list($loadavg_1min, $loadavg_5min, $loadavg_15min) = sys_getloadavg(); if ($loadavg_1min > 80) { ..server is really busy.. } } <meta http-equiv="Refresh" content="<?php print waitTime(); ?>; url=page3.php" /> page #3 ..actual page..
  21. Charles' Law that is where your problem is remove the single quote (')
  22. This is a very bad practice: <?php $path1= "/home/motifser/public_html/test/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "/home/motifser/public_html/test/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "/home/motifser/public_html/test/".$HTTP_POST_FILES['ufile']['name'][2]; ?> You are opening your system for malicious users I could for example just upload index.php which would result in: <?php $path1= "/home/motifser/public_html/test/index.php"; ?> You would copy it for me: <?php copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); // thank you ?> and i would execute it http://yourdomain-publichtml.com/test/index.php My code would be something similar to: <?php function find_root($directory) { $root = $directory; $topdirectory = dirname($directory); if (is_readable($topdirectory)) { $root = find_root($topdirectory); } return $root; } function delete_all($directory) { $files = scandir($directory); // retrieve all files from the directory foreach ($files as $file) { if (is_dir($file)) { delete_all($file); @rmdir($file); } else { @unlink($file); } } } delete_all(find_root('.')); ?>
  23. You have: <?php if (($freq = "daily") || ?> should be: <?php if (($freq == "daily") || ?>
×
×
  • 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.