Jump to content
MakeWebGames

Floydian

Members
  • Posts

    900
  • Joined

  • Last visited

    Never

Everything posted by Floydian

  1. Re: Help please Nyna, I'm on top of these ctype functions, and the filter functions that were put in with php 5.2, cuz I am a slacker when it comes to regular expressions. lol Don't even ask me to code an email regex, let alone explain how one works :D I'm lucky to have figured out how to do the ereg_replace deal I posted as that's about the extent of my regex expertise. hehehe
  2. Re: Help please I was focusing on how to only allow letters, numbers, spaces, and underscores. ;-) And the function for displaying a form was purely an academic example of the logic I use in these situations. I believe it's better for people to actually code the functions themselves than to copy and paste so it was not intended to be "usable". But thanks killah for adding that ;)
  3. Re: Help please From the PHP Online Manual: Beginning with PHP 4.2.0 these functions are enabled by default. If you're working with PHP < 4.2.0 you really should upgrade. ;) But with that said, I don't wanna take away from the code Nyna posted. We have two different flavors for doing the same thing, although mine allows spaces ;) teehee
  4. Re: Help please What about spaces? I like spaces :p Okydokie, I'll take a crack at it ;) and show you my personal flavor of validation :D   if (!ctype_alnum(ereg_replace('[ _]', '', $_POST['newname']))) { echo "Only letters, numbers, spaces, and underscores are allowed."; die; }   I'll break that down a bit for you in case you're not familiar with the functions used. ereg_replace('[ _]', '', $_POST['newname']) That removes spaces and the underscores from the string (note that I do not use this function to remove the spaces and underscores for the purpose of storing this in a variable, it is only so the ctype_alnum() function can do it's thing properly). !ctype_alnum( [(string) with spaces and underscores removed] ) The cytype_alnum() function tests if a string is an alphanumeric string (only letters and numbers). If anything other than that is found, it returns FALSE and thus we test for a false value. It is necessary to remove the spaces and underscores before using the ctype_alnum() function because spaces and underscores will cause this function to return false.   I did not include any escaping code as in the previous post though, so keep that in mind. If $_POST['newname'] is found to only contain letters, numbers, spaces, and underscores, it will still have the spaces and underscores in it and you can now store in the database.   You may prefer to use an if...else block which would allow you to not have the die function in there like I have it, or if you encapsulate all of this inside a user created function, you can substitute return; for die; and in that case the function is exited and the script can finish execution as normal, but without having stored the name in the database and the error message would be displayed. Using return; is the prefered method for me since you can do something like:   if (!ctype_alnum(ereg_replace('[ _]', '', $_POST['newname']))) { echo "Only letters, numbers, spaces, and underscores are allowed."; display_name_form(); return; }   Since your form should be in a function itself, and the validation/database insertion/update code in another function, you could upon detection of an invalid name, call up the function that displays the form and then exit the function the executes the database insertion/update. This negates the need for a back button where a page is displayed with the error notice and then the user is required to "go back" to the form since the form could simply just be redisplayed immediately for the user thus improving the users experience ;) In the form function, you could take it a step further, and do:   function display_name_form() { if (!isset($_POST['newname'])) { $_POST['newname'] = null; } echo <<<EOT <form blahblah> <input type="text" name="newname" value="{$_POST['newname']}"> </form> EOT; }   And doing that, will redisplay the name they put in the form so they can simply edit it, instead of retyping everything ;) The if(!isset blahblah) deal is used to initialize the variable the first time the form is displayed so that an E_NOTICE is not generated due to an uninitialized variable. D: :mrgreen:
  5. Re: Help please I wouldn't allow folks to use special characters in there names. Just allow letters, numbers, spaces and underscore, and you'll be fine.
  6. Re: Phone calls/Texts soz man, couldn't resist ;)
  7. Re: LEFT JOIN read this: http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php and if you have any specific questions, post them ;)
  8. Re: tune.php help you gotta define the function power obviously, it isn't a function that is predefined in PHP where did you get the mod? is it a paid mod, free mod, make it yourself? we'll need to know what it's supposed to do to help. or you could contact the person that wrote it
  9. Re: Quick help please killah, you are simply wrong about how your code would work. first and foremost, the $r variable WOULD NOT be set before the header executes so it's pointless, and I know you could not have tested the code out, and if you did, you would see that it would not work that way. aye caramba....
  10. Re: Please help with time in header you get a unix timstamp doing that. perhaps you should read up on the time() function or experiment with it a bit ;)
  11. Re: Quick help please soz killah, there isn't much I can do with that. It looked interesting, but closer inspection showed me number one: you did select * which would be a big waste if all you want is the username... Secondly, that will only affect one username, not all usernames on a page. so, there's no sense in adding that to the header if it can't add color to all usernames. Personally, I take userid's in the database, and run them through a function I call: profile() that function is used everywhere there is a clickable username, and it can make usernames colorcoded :-) if you want it too. but, ya gotta add the function in everywhere you want to use it.   This is not mc code compatible code, but it demonstrates the idea of what my profile code does. Adding in user_level to the query, and then colorizing the names accordingly from there would be a snap, and it's something I may do at some point. It'd take all of 3 minutes to colorize every name on my site ;) // Link to user profile function profile($id) { $q = sprintf('select username, user_id from users where user_id = %d limit 1', (int) $id); $query = query($q); if (mysql_num_rows($query) < 1) { $username = "User does not exist"; } else { list($name, $id) = fa($query); $profile = <<<EOT [url="index.php?p=view&case=view&user_id=$id"]$name[/url] [$id] EOT; } return $profile; }
  12. Re: itemmarket.php help RE: Zeon What's the difference in calling a function before or after it's defined? There are two things to consider:   Secondly: It's considered a "best practice" to define functions before you call them, and to define them at the beginning of the code. You wouldn't want a professional Zend coder to look at some code and thing, dayum, who wrote this?? *wink wink*
  13. Re: Quick help please it sounds like your html code isn't properly formatted. It's most likely missing an apostrophe somewhere.
  14. Re: Quick help please What error comes up that prevents sending mail like that? And why would the colorized name even be in the mail itself?
  15. Re: Phone calls/Texts Well, I guess your name here is appropriate. General doom: a state where you are generally suffering doom.
  16. Re: Phone calls/Texts Can't you block their numbers? I'm willing to bet you can get your cell company to block em. Hopefully you're not under a contract and can threaten to switch service if they are stubborn about it.
  17. Re: Phone calls/Texts I'm sure my advice will be discarded, but you are certain to make things worse by engaging in the same kind of thing those people doing. I'd let it go. What can you really do? so, you sent 1000 text messages, big woop. I think they'll get a kick out of that
  18. Re: Effienciecy $q=mysql_query("SELECT u.username, u.userid, g.gangPREF FROM `users` u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN gangs g ON g.gangID=u.gang ORDER BY (us.might+us.stealth+us.defence+us.force+us.IQ) DESC, u.userid ASC LIMIT 20", $c); You could take that query and try this: $q=mysql_query("SELECT u.username, u.userid, g.gangPREF FROM `users` u LEFT JOIN gangs g ON g.gangID=u.gang order by (select (us.might+us.stealth+us.defence+us.force+us.IQ) from userstats as us where u.userid = us.userid) DESC, u.userid ASC LIMIT 20", $c); I'm not guaranteeing that that will be faster, but it's another way to do the same thing. Another thing you can do is put an index on columns you use to match things with. u.gang would be a good one.
  19. Re: v1 to v2 ??? mysql_num_rows should work just fine on a vs 2 game. It should work fine in php any time you're using the regular mysql extension (not the improved mysql extension) and if you have a mysql result resource stored in a variable or an object.
  20. Re: Need some help Dur's mor din 2 ways ta sk'n a wabbit...
  21. Re: hole page opacity. That's equivalent to saying: Having text on your site is bad because a lot of people are illiterate. It's their fault. They need to enable it. It's akin to refusing to use electricity (aka Quakers) because it's somehow bad. lol Get with the program folks, and live a little.
  22. Re: Tutorial: v2 - v1 Conversion assuming your mysql.php file (or whatever the file that contains your mysql connection is call) is included in your cron file, and assuming the variable containing the connection is named $c, you can change: $db->query to mysql_query and add in a second argument to the function i.e., mysql_query($string, $c) instead of $db->query($string)
  23. Re: hole page opacity. Just a theory, but when doing onmouseover, you can use "this.value" or some variation of the "this" object. So, I'm thinking naming a variable "this" in the argument of the javascript function is probably not the best way to do. Try changing every instance of "this" to "this1" in the function.
  24. Re: hole page opacity. you'll probably want to go with "onmouseover" HTML DOM events to trigger javascript code that can swap out your bg's/images I am not fond of writing javascript, so I'm not writting any for free. soz
  25. Re: Cron Optimization question For the select using the count(*) function be faster. then list($count) = mysql_fetch_row($db->query("SELECT count(*) FROM users WHERE hospital > 0")) count(*) in this context would be counting rows, and would not be operating on individual columns. For this reason, the spot where count(*) is used, it works out good.
×
×
  • Create New...