Jump to content

mikesta707

Staff Alumni
  • Posts

    2,965
  • Joined

  • Last visited

Everything posted by mikesta707

  1. yes, just use the square bracket operator to supply whatever index you want $key = 45 echo $_SESSION['item'][$key];//echos 2 //store the 2 from $_SESSION['item'] in a variable $two = $_SESSION['item'][$key]; //alternatively, this will also work $two = $_SESSION['item'][45];
  2. if you cant use the query, then per teddy's suggestion if($pos !== false){ echo "checked=\"true\""; } you would think === would also work, but it doesn't. Because $pos will return a number when true (like 3, or 4) when using === it fails because the number 4 is not identical to the boolean false. it is convertible to it, but === (identical) means that the right hand side and left hand side or both equal in value and the same type
  3. or just do $keys = array_keys($_SESSION['items']); $str = implode($keys, ','); array_keys(): http://php.net/manual/en/function.array-keys.php dam teamatomic beat me to the punch. but posting anyways for manual link
  4. mikesta707

    $_GET

    Ahh I thought I had misunderstood, but posted that anyways. I wasn't saying that session vars are buggy. I use them all the time, and of course know that they are standard and all that jazz. But trying to use session vars to emulate sending data though a link with get variables would be very buggy (which is what i originally thought you were trying to say) if at all possible. However, I don't quite understand what you meant by your suggestion. specifically the don't use them part.
  5. in your query itself you can use wildcards in combination with the LIKE operator. for example ] $q = "SELECT * FROM Table WHERE column LIKE '%search term%'"; will match any row where column has "search term" in it. the % act as wild cards.
  6. well then I would start with a tutorial on the $_GET array. here's a good one then start learning about SQL and using it with your database. The most common database I see used around here is MySQL (good starter tutorial) and after that it should be pretty straight forward
  7. alternatively you can store all valid pages in an array, or a datebase, and check that way. It would probably look a little cleaner than a long switch block (especially if you have a lot of pages) but would work more or less the same. for example, using an array $valid_pages = array("home", "main", "etc", "etc"); $mode = $_GET['mode']; if (!in_array($mode, $valid_pages)){ //redirect to error } in array: http://php.net/manual/en/function.in-array.php
  8. probably because you just copy pasted his example without trying to understand it. You need to change the array key in =$row['owner field from players']; to whatever the column is called in your 'players' table that has the value of the 'owner' column in your 'garage' table. just a word of advice, usually copy pasting code you get from a help forum won't work. you actually have to take the example, understand why it works, and alter it to work with your code. in your case the alteration was very minor... but crucial to the code working
  9. mikesta707

    $_GET

    I wouldn't suggest not using them... $_GET and $_SESSION both have their place. $_GETs are useful for passing information to a page via a link so your pages can be more dynamic for example (just 1 of many uses). doing something similar with sessions would be buggy and much less clean. As far as protecting values goes, if you use the values in queries, always remember to use mysql_real_escape_string() on string input (assuming you aren't hashing it) for numeric values (or rather, values you expect to be numeric, like id's), always cast them as ints, to avoid getting strings which could contain nasty injections. Restricting the length of your $_GET values can help too (like Id's are never longer than 10 characters or something.) sanitizing input is very important, but not always clear cut and straight forward. Think about what kind of information would be valid for your $_GET values, and check them according to that. If you want to get fancy, using regex to detect valid patterns would help also (like detecting a valid email string)
  10. well in that case you could store referal ids/links in relation to someone's IP address rather than the conventional user name and password combination. You could store the stuff in a file, but using a database would be far easier to manage/maintain, and add more code on top of. as monkeytooth said, my example was just a starting point though, as there are quite a few things to consider. I would suggest starting with a simple table that stores IP address, the referal link code (which you can generate how ever you how, however, I would suggest hashing the IP address, via md5 or another hashing algorithm, or something, as thats probably the simplest way to do it), and number of referals and try to get the referals counter working. after that you can worry about the more complex problems like repeated link clicking. For this problem, monkeytooth's solution would probably work rather nicely and simply
  11. well for each user in your table, you could just have a counter to keep track of how many referels there have been. In your referal link, you would put an id or something unique to each row, and update the table with a query like $id = $_GET['id']; $sql = "UPDATE table set referals = referals + 1 where id = $id"; .... then you could do something like //get id from database with query $num = $row['referals'];//get number of referals from table row array if ($num > 5){ //show some pic } if ($num > 10){ //show another pic } //etc
  12. oh, sorry try if($PhpTagCheck !== false){ apparently it has trouble with === the followign works for me $contents = "some string with <PHPdd> in it"; $PhpTagCheck = '<PHP>'; $PhpTagCheck = strpos($contents, $PhpTagCheck); if($PhpTagCheck !== false ){ echo "good"; //header("location: http://www.google.com"); } else { //return "It dosn't work"; echo "bad"; }
  13. strpos() str_pos usually doesn't return false, but a boolean value that can evaluate to false. Because of that, you should use the === operator if($PhpTagCheck === true){} else {}
  14. what version of php do you have? that seems to rely on an old setting that has become deprecated. instead of $cmd try replacing occurrences of that with $_GET['cmd'] btw the equivalent of lists in PHP are known as arrays. I don't believe there is a data structure in PHP that is like a tuple though.
  15. eval() but if you are executing user input, thats not such a good idea
  16. I started programming in some language called Liberty Basic (which now that I think about it, was really weird. Don't know why i didn't just use visual basic) around 12 years old and since then i'd been very interested in programming/computers/etc. My first real programming language was PHP, which i learned about a year later (along with HTML/CSS/Javascript). Since then i have tried a few difference languages. Now im a CS major in college, working on C++ algorithms and crap like that. I was gonna write a pretty long response, but got lazy about half way through
  17. if you want a check box to be selected, you need to set its "selected" attribute to the value "selected". for example <option selected="selected">...</option>
  18. what is happening? is there an error? code not doing what you want? a little more info would be needed to give a concrete answer. the function looks ok to me, but seeing the function call itself would probably help also. edit: oh, didn't even see the scroll bar in second code snippet... yeah thorpe is right.
  19. those double quotes are what is causing the problem, but OP's code is still unclear at best, and completely arbitrary and useless at worse. What exactly are you trying to do? because whatever it is, I don't think that code will do it.
  20. that was weird. whole post wasn't sent. nevermind
  21. i suspect its this line $message = "$naam", "$adres", "$postcodeplaats", "$tel", "$fax", "$email", "$offerteaanvraag", "; kind of strange looking. are you trying to concatenate that stuff together" of have a string with that stuff seperated by commas? if first $message = "$naam". "$adres". "$postcodeplaats". "$tel". "$fax". "$email". "$offerteaanvraag"; if second $message = "$naam, $adres, $postcodeplaats, $tel, $fax, $email, $offerteaanvraag";
  22. that means that the directory/file you are pointing to doesn't exist. Remember, you are giving a relative path, so make sure that the file is where you expect it to be
  23. yes, yes that should do exactly that (assuming the script is in the same directory as the documents directory)
  24. you could use modulus $mod = $id % 3; if ($mod == 1) { ... } else if ($mod == 2) { ... } else if ($mod == 0){ ... }
  25. well clearly the query isn't finding anything. but since its all locked away in that class I can't be of much help without seeing the class internals
×
×
  • 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.