Jump to content

rmbarnes82

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

Everything posted by rmbarnes82

  1. Wasn't meaning to attack your post, its just I really wanted to get across to OP that what he's doing is wrong on a fundamental level, so he needs to completely rethink his whole approach, not look for optimizations to what he currently has.
  2. Hi, You have a problem with how you have conceptualized the database design, not with your client side coding. You need a user table in your database, representing the user currently playing the game. The round round 1, round 2, round 3 rows need to be associated with the user somehow, or you could even just store them in the session. A possible design for this in terms of the database is (I am presuming the seed stays constant here): surfer ------- id seed user -------- email password game ------- id user_id game_surfer ---------------- game_id (primary key) surfer_id (joint primary key) round1 round2 round3 Then just use the session to keep track of the users current game id. Robin
  3. Hi, For form containing a tuple, also generate a hidden form field inside the given form containing the primary key (id) for that row in the database. E.g.: <input type="hidden" name="row_id" value="$rowId" /> Then the submitted row_id value is the id you want to use in the where clause of your delete statement. Robin
  4. Hi, Is the reason you need to know which button was clicked so you know which row in the database the submitted tuple refers too? Robin
  5. You mean the user pretending to be paypal and send back a purchase successful form to your website?
  6. Hi, Not strictly a PHP question, but meh. You problem is the way you call the CountWords function: <input type=button value="Count Words" OnClick ="CountWords(this.form.x, true, true);"> You use this.form.x to identify the text area, not no form exists. To fix this: 1. Give each text area a unique id, eg: <textarea id="text1"></textarea> 2. Call CountWords using the textarea's id, so for text1: <input type=button value="Count Words" OnClick ="CountWords(document.getElementById('text1'), true, true);"> Robin
  7. Don't paypal use some sort of secret key only you and they know, then use that and a hashing algorithm they give you to encrypt the form data?
  8. That usually only happens if you actually take the payment details on your own site. Usually with stuff like paypal you hash the cart contents then post it to the payment provider. It's just there to stop ppl altering the form (eg changing all the product prices to 1 cent to rip you off). Far better to send the post form using curl.
  9. Hi, The general rule of thumb is filter input, escape output. What you are doing sounds right. 1. Turn off gpc_magic_quotes 2. Use mysql_real_escape_string on all variables which are added to MySQL queries (note that addslashes may *not* be effective. I've heard that people can use hex codes to inject stuff into your DB, addslashes won't stop this). 3. Use htmlentities on all output which has come from the user which is not meant to display as html (if you have a cms system you may want to display user input as html). This isn't just stuff out of the database. Take a search box. Most sites have a search box, and after the user has searched the results page displays the search term, eg 'You searched for "xxx"'. This search term never gets saved in the DB, but people can type JavaScript into the search box to create an iframe (which could show a competitors website). Not a major risk but can make you look quite amateur. Robin
  10. Hi, PFMaBiSmAd is right. Gziping your script / output is basically pissing in the wind here and won't help you. Your program as is will time out with 100,000 rows in the database. I think you need to provide a detailed account of what you want your script to achieve, as your whole approach seems wrong. Robin
  11. <?php $string = 'this is a string&more=this is some more stuff'; if(($pos = strpos($string, '&')) !== false) $string = substr($string, 0, $pos);
  12. Hi, What are you trying to accomplish? Will a user view this page or is it just some kind of automated maintenance script? If it's a maintenance script then viewing via the web is the wrong way to go about this. Robin
  13. Hi, Are you really looping through all 2000 rows in the database table in that script? If so thats always going to be slow.
  14. Hi, As the previous poster pointed out you need to use a technique called recursion: http://en.wikipedia.org/wiki/Recursion_(computer_science). Recursion is cross language, and is usually implemented as a function which calls itself. This is one of the more complex techniques in programming, and some people never understand it. Here is an example of the standard way to print the numbers 1 - 10: for($i = 1; $i <= 10; $i++) { echo $i . PHP_EOL; } To do the same using recursion, you could do the following: <?php function printNums($num) { if($num < 1) return; printNums($num-1); echo $num . PHP_EOL; } printNums(10); Note that the printNums function is recursive because it calls itself. In terms of looping through an array of unknown depth, you would probably need a function which took an array as the argument. If the function was passed and empty array, it would return. If the array was not empty, it would call itself with the arrays child array as the argument. Robin
  15. Hi, You seem to have 2 problems here. First remove all of the brackets from your SQL query, they don't need to be there. Second, the SQL error seems to be caused by the fact that $catid is empty, hence WHERE catid = ) in your SQL error. Robin
  16. Hi, Your getting a bit confused, swissbeets. Firstly, your code: <?php $twodays = strtotime("two days ago"); DELETE FROM `cart` WHERE `cart`.`cookie_id` = .$twodays; The value held in $twodays represents two days ago to the exact second. This means your query will only delete carts created exactly two days ago to the exact second. You need to delete all carts over two days old, so it needs to be: <?php $twodays = strtotime("two days ago"); $query = "DELETE FROM `cart` WHERE `cart`.`cookie_id` <= $twodays"; Secondly I don't think you understand cron jobs. Are you using a Linux server? You can't get cron jobs on a windows server. A cron job is an entry in a cron file (not a PHP file) which tells the cron daemon to run a command based on a certain schedule. Your command would look something like this: /path/to/php/binary/php -f /path/to/script/delete_carts.php For more on cron jobs see http://www.unixgeeks.org/security/newbie/unix/cron-1.html or just google 'cron job tutorial' Robin
  17. Hi, Do you mean you don't know how to organize your database tables to allow this? Robin
  18. Hi, If you're going to do this you really should use some form of query caching, I don't know if MySQL does this automatically. What you really want to be worried about is Denial Of Service. If too many people use this webpage at the same time, apache will probably turn of because it is receiving too many requests too quickly. Google 'denial of service' for more info. I think what you have to ask yourself is: does it really matter to the users if the data refreshes every second, or could it be every 10 seconds? Also you could use ajax to just update the part of the page that was dynamic, rather then reload the whole page each time. Robin
  19. Hi, The time() function returns a UNIX timestamp. A UNIX timestamp is the number of seconds since a date known as the epoch (which was 00:00 on 1st of Jan 1970 if I remember correctly). So what you need is to be able to work out a timestamp which is 2 days in the past, and delete all cart items earlier than that. The hard way would be to work out the number of seconds in two days, and subtract that from the current time(). PHP, however has a really usefull function called strtotime. This takes a wide variety of date / time representations in a string form and turns them into a unix timestamp. In short, the timestamp for two days ago could be go by doing strtotime("two days ago"); Robin
  20. Hi, This is really a useabillity question. Most users would expect to check all the checkboxes they want, and then click on a submit button to save it. If they just check a box, how are they going to know that their selection has been saved? Unless you let them know it has they will assume your app is broken. Also, if you are going to submit one checkbox at a time, make sure you do it using ajax. If you don't the page has to be re rendered each time they check / uncheck a box which is very inefficient. Robin
  21. Hi, I would just store the customers cart_id in the session like this: $_SESSION['cart_id'] = $cart_id; Then on each page load just use the created session variable to retrieve the cart_id, then based on this load the cart from the database. This of course means that if the user's session times out (usually after like 15 minutes of inactivity on most systems), the cart gets emptied. I just think you have to live with that if you don't want them having a user account. Also, I don't mean to throw a spanner in the works, but you do realise that the cart table only allows for one product per cart, right? Robin
  22. Hi, The answer to your question is yes and no. Yes you can reach the figure 1000 from the numbers given, but only if you use a higher precision. Based on 365 points being 36%, the total points would come out at around 1013. The correct percentage is 36.5%. Using this we can get 100: <?php $currentPoints = 365; $currentPercentage = 36.5; $totalPoints = (100 / $currentPercentage) * $currentPoints; Robin
  23. Yeah, I only noticed one bug, not the echo bug also.
×
×
  • 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.