scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
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>';
-
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>'; }
-
This is a long shot...but here it goes
scootstah replied to son.of.the.morning's topic in PHP Coding Help
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? -
$blacklisted is number(s) that aren't allowed. $_SESSION['code'] is the number you are trying to guess.
-
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
-
No, you can just do: $blacklisted = 717; // ..... if ($code != $blacklisted && $_SESSION['code'] == $code) {
-
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.
-
Wordpress permalinks showing urlencoded unicode characters
scootstah replied to watsmyname's topic in Applications
What is the title of the post? -
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.
-
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>';
-
Have you tried something like this? http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/
-
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'; }
-
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>'; }
-
Creating a function that add a string into a text box
scootstah replied to son.of.the.morning's topic in Javascript Help
Here it is in jQuery: http://jsfiddle.net/RjwS8/ -
I think you got your logic flow mixed up. Remove the ! from in_array().
-
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().
-
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.
-
Looking to create a shopping cart, Any good tutorials....
scootstah replied to laflair13's topic in Miscellaneous
Use the CodeIgniter framework with the cart class. There's pretty good documentation on it. http://codeigniter.com/user_guide/libraries/cart.html -
Your function works for me.
-
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'));
-
Function Runs 100 Queries - Need This Reduced!
scootstah replied to unemployment's topic in PHP Coding Help
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. -
Function Runs 100 Queries - Need This Reduced!
scootstah replied to unemployment's topic in PHP Coding Help
I'm pretty sure that shows the total queries ever executed on the server. But I may be wrong.