Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Do you have an algorithm that you would like to implement in PHP, or are you at the stage of looking for an algorithm?
  2. From the manual page of exit(), for which die() is an alias: In other words, use something other than die() to print out the number of rows.
  3. It all depends on what you are trying to prevent. If you want to stop dedicated spammers, you need Captcha. If you want to stop casual users playing around, checking the referrer is probably enough. A posting timeout might also be appropriate, such as making people wait at least 60 seconds between posts, if spamming is what you are trying to prevent.
  4. You could put each column value in a text box, and have a submittable form. Or you could use a toolkit such as Dojo to make a nicer looking form. For this sort of thing I suggest you have a go at some tutorials on google, and then ask here if you are having trouble. Make sure you post whatever code you are working with when you ask here.
  5. It's impossible to stop someone making a request directly to a file called through Ajax. But what you can do is use some sort of authentication, the type depending on what you want to achieve. If you want to stop spam, you would use a Captcha. If you want to authenticate the user, you would store the user id in session data and use that in add_comment.php, instead of expecting it to be passed via Ajax.
  6. Can I suggest a few changes: $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' ORDER BY name"); if (!$query) { # Change 1 - Only echo error if query failed, and exit script if query fails. echo mysql_error(); exit(1); } while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) { # Change 2 - indent contents of foreach loop, and put { and } on their own lines $i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); # Change 3 - $FileName can be used below instead of repeating the str_replace() echo "<a href='$FileName?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents"); } fclose($FileHandle); The changes are to improve error handling (stop the script if query fails), readability (make it clear what's in the loop and what's not) and to remove duplicated code (the str_replace).
  7. Ok now that the typo is fixed, could the problem be that your order of operations is this: 1. Increment $i 2. echo $nt[$i] and $FileName 3. Set $FileName from $nt[$i] The problem being that you set the filename after displaying it, not before.
  8. It does make a difference if you are interpolating variables, yes, but the OP was concatenating them. I was comparing his original approach to your approach, not comparing interpolation without brackets to interpolation with brackets. Thanks for the clarification though, I can see how it might be misinterpreted.
  9. They don't make a difference here. But I think it's easier to read {$var} instead of ".$var.". So it's a matter of taste really, either way works. {$var} looks nicer with the syntax highlighting I use in my php editing software (vim).
  10. The simplest way to do this is just to select inv_count - total_reserves, rather than making a new column. If you are integrating with existing software that needs the after_reserves column, then you could make a trigger that updates that column whenever the values it depends on change. Or you could create a view into that table, with the after_reserves column defined as inv_count - total_reserves.
  11. There's two parts to this, getting the data from the db and putting it into PDF or another printable format. I may be able to help with getting data from the db if you can be more specific about what you want.
  12. I do my queries like this: $query = "UPDATE {$prefix}users SET nickname = '{$nickname}' , gender = '{$gender}' , color = '{$color}' , profile = '{$profile}' , favpet = '{$favpet}' , about = '{$about}' WHERE username = '{$loggedinname}'"; mysql_query($query) or die("Query:<br />{$query}<br />Error:<br />".mysql_error()); It may look a bit funny at first, but notice that when you add a new column you don't have to think about whether or not you need a comma at the end, because every line except the "SET" line has a comma at the start.
  13. The equality test operator is "==". "=" is assignment. This is one of the most common programming errors, I am forever disappointed that PHP doesn't automatically warn programmers of this
  14. You could try setting top.location.href instead of window.location. I found that here http://www.thesitewizard.com/archive/framebreak.shtml so it may be out of date.
  15. Ok, sorted by keyword. You could do this: $keywords = array(); while ($row = mysql_fetch_array($result)) { $referer = $row[0]; IF($referer) { PREG_MATCH("/[\&\?]q=([^&]*)/", $referer, $matches); $search_query = RAWURLDECODE($matches[1]); $search_query = STR_REPLACE("+", " ", $search_query); $keywords[$search_query]++; } } ksort($keywords); foreach ($keywords as $k => $c) { print "$k ($c)<br>"; } You might also want to use strtolower() on the keywords if they don't already have standard capitalization.
  16. You've got 2 different variables there, $filename and $FileName. The lowercase one, $filename, doesn't appear to be set anywhere in your code.
  17. By "group and sort" do you mean count how many times each $search_query appears and put them in descending order?
  18. Have you managed to solve this? I'm asking first since it's such an old topic.
  19. I still don't understand - you have given me a formula in PHP, and you are asking me if it is correct. How can I tell you if it is correct unless you tell me what you are trying to calculate?
  20. What formula are you trying to implement?
  21. Yes that's pretty much right. Session data can't be altered directly, so it's good for storing things like the user id of the currently logged in user, and remembering if they have administrator access or normal user access. Things like the forum topic being viewed are fine to have in get or post, as they are intended to be changed by the user. You can still validate them against the user id in the session to make sure that user has permission to view that topic, for example. To add to what QuickOldCar said, GET is good for things where it doesn't matter if they are done twice, like viewing a topic. POST is good for things which should be done once only, like submitting a new topic.
  22. That's an odd data structure. You can print them out like this: $lastAry = array('smith', 'jones', 'reed', 'chan'); $firstAry = array('mary', 'chris', 'kim', 'joe', 'sara', 'tim', 'amy', 'fred'); $names_count = count($lastAry); for ($i = 0; $i < $names_count; $i++) { print "{$lastAry[$i]} | {$firstAry[$i*2]} | {$firstAry[$i*2+1]}\n"; }
  23. You have one submit button named "true" and another named "false". You should find the respective values in $_GET['true'] and $_GET['false'].
  24. That will give you a different random order every single time. The select should be SELECT * FROM table ORDER BY band, rand_order in order to use the stored order that is updated each week with cron.
  25. That's odd. Do you store the incoming data directly into $_SESSION without any modification?
×
×
  • 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.