Jump to content

scootstah

Staff Alumni
  • Posts

    3,858
  • Joined

  • Last visited

  • Days Won

    29

Everything posted by scootstah

  1. Always the number 300000? That makes it substantially simpler. if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['code'])) { $code = $_POST['code']; if ($code == 300000) { echo 'correct'; } else { echo 'incorrect'; } } } echo '<form action="test.php" method="post"> <input type="text" name="code" /><input type="submit" name="submit" value="submit" /> </form>';
  2. I tried this and it just returned the "Select one..." option, with nothing in the dropdown. Sorry, actually tested this time: function dropdown($array, $id, $selected = '') { echo '<select name="'.$id.'" id="'.$id.'" class="select"><option value="">Select one...</option>'; foreach($array as $key => $value) { echo '<option value="'.$value.'" ' . ($value == $selected ? 'selected="selected"' : '') . '>'.$value.'</option>'; } echo '</select>'; }
  3. I strongly disagree. Number one, any editing will need to be UNformatted, and number two you destroy the ability to reuse the data. What if you ever want to format it in a different way in the future? What if you change your algorithm? What if you want to use the data in a different way?
  4. $blacklisted is number(s) that aren't allowed. $_SESSION['code'] is the number you are trying to guess.
  5. A 3 second Google and this appears to work for me: http://www.sitepoint.com/forums/showthread.php?276177-how-do-i-make-iframe-height-100-in-firefox&p=1996248&viewfull=1#post1996248
  6. No, you can just do: $blacklisted = 717; // ..... if ($code != $blacklisted && $_SESSION['code'] == $code) {
  7. You could use headers to change the content type to an image, then just use the php page in your img src. But in the long run saving the file will drastically reduce server load.
  8. What is the title of the post?
  9. In my opinion you are over-complicating this function. All it should be concerned with is if value == selected. What the value of selected is should be pre-determined; whether it be array keys or not.
  10. Okay I think I know what you are trying to do. I've rewritten your script, does this do what you want? session_start(); $_SESSION['code'] = 79; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $blacklisted = array(796574, 7, 2, 3, 4, 5); if (isset($_POST['code'])) { $code = $_POST['code']; if (!in_array($code, $blacklisted) && $_SESSION['code'] == $code) { echo 'correct'; } else { echo 'incorrect'; } } } echo '<form action="test.php" method="post"> <input type="text" name="code" /><input type="submit" name="submit" value="submit" /> </form>';
  11. Have you tried something like this? http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/
  12. With this code I get "incorrect" - is that not what you wanted? $blacklisted = Array("796574", "7", "2", "3", "4", "5"); //$code = $_POST['code']; $code = 2; if( in_array( strtolower($code), $blacklisted ) ) { //$emailblock = '<div id="captchatext">Sorry, that number was not 300000.</div>'; echo 'incorrect'; } else { //require('send.php'); echo 'correct'; }
  13. Whoops, typo. Here you go: function dropdown($array, $id, $selected = '') { echo '<select name="'.$id.'" id="'.$id.'" class="select"><option value="">Select one...</option>'; foreach($array as $key => $value) { echo '<option value="'.$value.'" ' . ($value == $selected) ? 'selected="selected"' : '') . '>'.$value.'</option>'; } echo '</select>'; }
  14. Is there a public link to your page?
  15. Here it is in jQuery: http://jsfiddle.net/RjwS8/
  16. I think you got your logic flow mixed up. Remove the ! from in_array().
  17. Try this: function dropdown($array, $id, $selected = '') { echo '<select name="'.$id.'" id="'.$id.'" class="select"><option value="">Select one...</option>'; foreach($array as $key => $value) { echo '<option value="'.$value.'" . '($value == $selected) ? 'selected="selected"' : '') . '>'.$value.'</option>'; } echo '</select>'; } Just pass the value from the database as a third parameter to dropdown().
  18. You might be able to make a more dynamic solution from this: function segment($index = 1) { $segments = explode ('/', $_SERVER['REQUEST_URI']); if (!empty($segments)) { array_shift($segments); return $segments[$index - 1]; } return null; } To use, simply count the number of "segments" after your domain and there you go. So in "www.something.com/something/10001", doing echo segment(2) would echo "10001". EDIT: By the way I didn't rigorously test this, just a push in the right direction.
  19. Use the CodeIgniter framework with the cart class. There's pretty good documentation on it. http://codeigniter.com/user_guide/libraries/cart.html
  20. Your function works for me.
  21. protected $db_fields = array(); public function __construct($fields) { $this->db_fields = $fields; } Then when you instantiate the class just pass the tables to it. $class = new class(array('id', 'name', 'address'));
  22. It still might not be accurate though, unless your app is the only thing connecting to the server. The only way to reliably count queries is to...well, count queries. Make a wrapper for mysql_query or something that automatically increments a SESSION containing the total queries or something similar.
  23. I'm pretty sure that shows the total queries ever executed on the server. But I may be wrong.
  24. PHP has a default max_execution_time of 30 seconds, so this would terminate before that time limit is even reached.
×
×
  • 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.