Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. array_merge() will re-index a numerically indexed array if it is given as the sole argument.
  2. Try printing page before the switch, like this: print "page: " . urlencode($page); Is it what you thought it would be?
  3. The page is displayed in the user's browser .. so in that sense, it doesn't matter what OS the server is running when it comes to taking a screenshot. Is it really a screenshot you want, or just a record of what was displayed?
  4. 20 minutes is fine. The frequency with which a cron job runs should be inversely proportional to the work it does. For example, a cron job that does 1 hour of heavy processing should usually be run no more than once per day. But a job that does 1 second of processing can be run every 5 minutes without any adverse effects.
  5. Are you storing your array in a session? If not, it will be reset every time the script is run.
  6. Here's another try .. untested as I do not have mysql <?php $query = "SELECT `cf_users`.`id` from `cf_users` INNER JOIN `cf_users2` ON (`cf_users2`.`id` = `cf_users`.`id`) LIMIT 1"; $result = mysql_query($query); ?>
  7. The chances are 1 rare - 8.1% (0.1 * 0.9 * 0.9 * 100) 2 rares - 0.9% (0.1 * 0.1 * 0.9 * 100) 3 rares - 0.1% (0.1 * 0.1 * 0.1 * 100) This assumes you are drawing 3 cards, and you don't care which order you find the rares in. The basic principle is that the p(A and B) = p(A) * p(B), with probabilities expressed as ratios. 0.9 is the probability of NOT finding a rare in any single draw.
  8. I assumed the OP would know that he could alter the string before calling eval()
  9. You can create functions without a name with create_function(). But for what you want you will need eval(): $newfunc = 'function foo() { print "foo\n"; }'; eval($newfunc); foo();
  10. That is indeed what explode does .. if you get it as a string with commas as above, you can do like this $wrongAnswers_arr = explode(',', $wrongAnswers); $counts = array(); foreach ($wrongAnswers_arr as $wa) { print "Processing wrong answer for question $wa\n"; # Do whatever with $wa $counts[$wa]++; } Is that what you're looking for? If you want to aggregate the values before writing to the database you can create an array of counts, as I've shown above.
  11. It depends on how accurate the 45 days has to be. There's a number of approaches. 1. Have a cron job run every minute (or 5 minutes, 10 minutes, 1 hour, depending on your accuracy requirement) that deletes old entries 2. Have your scripts simply ignore any entry older than 45 days. 3. Have your scripts check each time they run and clear any old entries.
  12. Ooh, I almost missed it. You need to remove the single quotes around the column names. But you should keep them around the values. So $sql = mysql_query("INSERT INTO users (username, password, email, name, gender, signup_date) VALUES('$username', '$db_password','$email', '$name', '$gender', now())") or die (mysql_error());
  13. So you want to do nothing if the username is NOT found, but do something if the username IS found? Then you need to do this: if (mysql_num_rows($checkun) > 0) { print "Username already taken"; } That's all. You can't use "or die" with mysql_num_rows(), because mysql_num_rows() can return 0, and 0 will cause the "or die" to trigger.
  14. What it means is that the query found 0 rows. In other words, the username did not match. The next thing I would do is print out your query. You can do it like this: $sql = "SELECT username FROM users WHERE username='$username'"; print "<br>Executing query: $sql"; $checkun = mysql_query($sql) or die (mysql_error());
  15. That is a very vague description. Are you asking us to decide the probability of drawing rare, uncommon and common cards?
  16. Here is how I would approach the problem: $checkun = mysql_query("SELECT username FROM users WHERE username='$username'") or die (mysql_error()); if($checkun) {print 'Username found!';} print "<br>mysql_num_rows(checkun) = " . mysql_num_rows($checkun); $checkname = mysql_num_rows($checkun) or die (mysql_error()); print "<br>After mysql_num_rows()"; if($checkname == 0) {print 'Username can be used!';} OK, that does 2 things - the first print shows you the value of mysql_num_rows(). And the second print confirms that the script DOES really stop EXACTLY after mysql_num_rows(), and not somewhere a bit further down. I'm confident that those two together will find the problem.
  17. Notice: Undefined variable? You can fix that with $error = ''; at the top of your script. Then to check it later if (!empty($error)) { print $error; } If you keep using the same technique, printing out stuff, then I am sure you will find at least the location of the problem. Once you find the location and still cannot solve the bug, post here with the details.
  18. You can never assume things like this, especially when dealing with someone else's code Are you able to print out the value immediately before you do the calculation? And check that the spelling is identical? The only way such a simple calculation could fail is if the input isn't what you expected it to be.
  19. Do you mean you got the sum, not the product? Have you checked that those values you added are set to what they should be? It seems very suspicious that a simple calculation like that would give wildly wrong results.
  20. That's output from a "similar" script? Can you show us the similar script? Or show us the output from this script.
  21. There's a few standards.. here's some of the common ones if (something) { while (something) { do something } } Everything inside a condition or a loop is at a new level of indent. Another common style is this: if (something) { while (something) { do something } } Both styles make it clear where a loop and condition starts and ends. display_errors can be set with this code at the very top of your script ini_set('display_errors', 1); If the print checks do nothing, then that code is not running. Simple So you need to ask yourself, why is that code not running when I think it should be? It's likely one of the things you are testing is not what you thought it would be.
  22. PHP is not HTML, but PHP usually produces HTML. When you use PHP through a webserver and produce an HTML document, you must use HTML tags. PHP can be used from the command line too, or to produce text documents, CSV, Excel, etc etc, or to produce text inside pre tags and textareas, and that's where \n is useful.
  23. Sorry, I misread your post. I think I get it now. The 2 problems are 1. Correctly completed registration script shows blank page 2. Correct login at login.php displays login.php again Ok, to deal with blank pages you must make sure display_errors is on. If it is, and you still get blank page, then you can find the error by adding print statements to indicate how far the script gets before dying. In situations where display_errors is on but blank pages result, the problem is usually a logic error, and that can be found using print statements in places where you think the script should be running, and noticing that they don't run. For login.php, firstly you repeat the same query twice. No need to do that. But that's not the problem. I would also add some diagnostic print messages there, so you can see which code is really being executed. Given that you were able to login once only, the problem may be due to left-over session data. You can clear that using a web developer extension, such as Microsoft's IE developer toolbar, or the firefox web developer toolbar. It's likely that some of your problems are due to misleading indentation. You should make sure that the indentation of your code matches its meaning, otherwise it's very hard to interpret the logic.
  24. You've described the problems, but what is the behaviour you want? Instead of the problem behaviour. One problem I notice - mysql_num_rows() operates on the mysql result, not on the result of mysql_fetch_row(). So you should do like this: $checkun = mysql_query("SELECT 'username' FROM users WHERE username='$username'") or die (mysql_error()); $checkuser = mysql_fetch_row($checkun) or die (mysql_error()); $checkname = mysql_num_rows($checkun) or die (mysql_error());
×
×
  • 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.