Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. http://us2.php.net/time You have two values that represent seconds. Take the difference and divide by 60 (seconds per minute)...
  2. You can't. I don't know how many times this has to be repeated, but Javascript only occurs on the client and PHP only occurs on the server. AJAX is merely a means of invoking a request on the server without refreshing or reloading the current page. The request is made to the server, the server executes some PHP, the PHP spits out some plain text (as it always does), and then your Javascript interprets however you decide it does. I won't explain the process in great detail, here are some pictures to help: http://images.google.com/images?q=ajax+interaction+model&ie=UTF-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&sa=N&tab=wi I suggest you step through a couple of AJAX tutorials before you ask further questions about the topic. I would highly recommend researching the different Javascript event models as well.
  3. WHERE (id_cat=1 OR id_cat=2 OR id_cat=3 OR id_cat=4) AND field1=1
  4. What do you mean exactly? I don't see you trying to print anything to the screen? In any case, the slashes added by addslashes() are stripped out by MySQL. If you want to actually save the slashes to the database, you'd have to call addslashes() twice; I'm not sure why you'd want to do that though.
  5. I think I'd enforce grammar and force people to choose their profile layout from pre-approved graphic designs. I'd also delete Tom's account.
  6. echo "<input type=button name='save_" . $count . "' value='Save' onClick='submit()' disabled=1> "; echo "<input type=button name='delete' value='Delete' onClick='submit()'>"; I just wanted to point out that the reason $_POST['delete'] is not set is because you set the type attribute to button. If you want the button name to appear in $_POST the input type has to be submit <input type="submit" name="a_button" value="Go" /> Why in the heck are you using Javascript to submit the button anyways? You do realize if someone comes along with JS disabled they won't be able to use your form, right? I'm going to watch a movie, I'll check this again in the morning.
  7. As an owner of both its really hard for me to decide. The wii is definitely more convenient when it comes to making fresh juice due to the motion sensor controllers and I dread the thought of cleaning the cat box with a keyboard and mouse. On the flip side, there's nothing better for smashing spiders than a desktop PC in a server-tower case.
  8. If you visit the PHP script directly in your browser using the URL below, you see an error: http://www.johnwasem.com/write.php Error: Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in C:\Sites\Single8\jwasem\webroot\write.php on line 8 Error: Unable to open file So now you're back to what Orio started out by saying, do your PHP scripts have write access to this directory?
  9. So when I go directly to your script: http://www.johnwasem.com/write.php I get this: Parse error: syntax error, unexpected T_IF in C:\Sites\Single8\jwasem\webroot\write.php on line 10 You forgot a semi-colon after your fopen() statement.
  10. Yah, I understand how the whole thing works. But did you confirm that the data was sent correctly? Try and echo the contents of your $input variable in the script that's writing the file. Basically, everything your script looks correct and you should be getting some output into your file. You still never answered this question:
  11. Ok. But that still doesn't tell what is in your $input variable when your PHP script runs. Also, since you said this is coming from a .swf file, are you sure the .swf file is sending it to the correct server?
  12. Are you getting any sort of output? Are you seeing your "status=Done" message? You are writing $input to the file but I don't see $input defined anywhere; are you sure the variable contains anything inside it? Insert this into the script: echo "input len: " . strlen($input);
  13. I can't give you a sure fire way to do so but here is the general method. First, beware of any method that tells you to use the userAgent string. Checking the userAgent string is often the quickest and easiest method but it is also unreliable since they can be faked. The more proper method is to find a global variable or property that is specific to the browser in question and check for it's existence. For example, IE has a global window.event object used for event-handling and they also have a document.all array. I'm not sure when window.event was introduced, but for the sake of argument let's say it was at version 6. This means if you wanted to check for IE 5.5 or lower you could do something like: if(document.all !== undefined){ // We have an IE browser if(window.event == undefined){ // IE 5.5 or lower } } Again, I'm not saying the above code works or that those are properties you should be using. I'm saying that's the general method for truly detecting which browser the user is using. Using that knowledge and some google searching should land you with something you can use.
  14. <?php function myurlencode($text) { $text = str_replace("%", "%25", $text); $text = str_replace("&", "%26", $text); return $text; } $data = "textfile.txt"; // make sure it has 666 permissions $fp = fopen($data, "window2="); if(!$fp){ die("Error: Unable to open file"); } fwrite($fp, "window2=" . myurlencode(stripslashes($input))); fclose($fp); echo "status=Done"; ?>
  15. If I had to guess I'd say it's because you might be specifying an improper 2nd argument to fopen(): $fp = fopen($data, "window2="); Why don't you try testing the value of $fp to see if fopen() succeeds?
  16. IMO there isn't really much that you can do that isn't a pain in the ass in situations like this and I don't really think you save much time no matter how you go about it. You create a lot of work for yourself upfront. You have to constantly manage the mappings and it becomes difficult to remember which mappings go to which columns. For example, if you go with numeric indexes and are selecting and joining from several different tables it will be a mess to sort through. If you go with associative indexes eventually you'll have many associations named similarly that mean totally different things. The only effort this saves you is when the database changes are related to naming. From my experience, I tend to have to rewrite queries not because of table or column name changes, but because of added constraints, requirements, or extra columns. This means I'd have to go through and edit a bunch of existing queries anyways and the mappings would be primarily useless. The biggest time saver for me in dealing with this sort of stuff is a small shell script I wrote. Basically I just invoke the script with a search term and it very quickly searches through all of my source and finds every occurrence of the term for me. It then creates a text file listing of: file:line_no{tab}source Then I just view it in firefox and use the built in find & highlight all function to narrow it down or I copy and paste it into edit plus to manipulate it further and remove some lines. I know that's not much of a time-saver in this situation, but it's helped me clean up a ton of deprecated code.
  17. You realize you made a mistake with? foreach($sql as $sql) {
  18. When you sign up for a hosting account they typically create an e-mail account for you. For example, if you signed up with hosting company Foo with domain mysite.com and chose some_user as your account name with the company, you'd typically get an e-mail address of: some_user@mysite.com Whenever you use a mail function within PHP it will (usually) by default send from that e-mail account. If your hosting company provides you with the ability to create more e-mail accounts you could certainly do so (via some web interface of theirs) and then configure your PHP installation or a specific module to use that account. In short, yes, you always need an e-mail server to send e-mail, but the hosting company usually provides this for you. Anyways, you can usually get the most basic membership from a hosting company for like $3 for an entire month; just figure out what the basic functionality you require is and use the cheapest membership to test if it all works. Then if you don't like the host you can easily switch and you're not out a ton of money on your end.
  19. Why not use SELECT ... INTO OUTFILE ... http://dev.mysql.com/doc/refman/4.1/en/select.html
  20. MOD is a mysql reserved word. Try enclosing all of your full table and column names in back ticks, the unshifted tilde key.
  21. Since HTTP is an anonymous, stateless protocol there is no method that does 100% what you'd like it to. All methods of being able to uniquely identify a particular user are strictly opt-in and they all occur on the client side. As pointed out, you can't use IPs. While every computer in a school's computer lab might have a different IP internally to the school's network, I believe they all live behind the same IP as far as the outside world is concerned. So if you block by IP and someone in the computer lab votes you'll lock out everyone else in the lab. Cookies provide the only method of uniquely identifying a machine for any length of time. You're right that a user can disable them, but 99% of the time sessions use a cookie as well so it's a moot point. In other words, if cookies are turned off, your session solution won't work either. I'd recommend using cookies. Most people aren't going to go to the trouble of repeatedly deleting a cookie just to submit a poll answer multiple times. If the polls are so important that you really want to block multiple submissions securely (and you still can't really), then require users to have an account with a valid e-mail address.
  22. Well there goes all my intended fun. Darn it! Welcome to the forums (edit) This sort of reminds me when I was playing CS:S once. A player using voice chat sounded like a girl but insisted he was a younger guy so everyone was joking / laughing / and arguing about it. Then in the middle this really deep voice, probably the deepest I've ever heard, goes, "I'm 11." Classic.
  23. This code cuts down the number of queries run, not the number of loops made. The way I accomplish this is grouping all the FacIDs into categories: Active, Inactive, and then those that correspond to the truth table. Then I run a single query for each category (Active, Inactive, TTT, TTF, TFT, etc) for a total of 10 queries. You should also note that your original code never handled the situation of 'FFF', so my code just tries to set the field to NULL in the database. You could modify the switch statement to skip over that particular key if you wanted. Anywho, here it is. It's untested so there could be parse errors. In addition, it doesn't execute the final queries but just echos them out for verification. I suggest you make sure it's operating correctly before letting it loose on your data, or back your data up first. <?php $TTable = Array( // Define our truth table 'TTT' => 7, 'TTF' => 5, 'TFT' => 4, 'TFF' => 1, 'FTT' => 6, 'FTF' => 2, 'FFT' => 3, 'FFF' => 'NULL' ); $SQL_IDs = Array( // Group our IDs into arrays to limit the amount of queries 'Active' => Array(), 'Inactive' => Array() ); foreach($TTable as $key => $val){ $SQL_IDs[$key] = Array(); // create an array for each truth table key } $q = "select FacID From `".F_TABLE."` Order by FacID"; $r = mysql_query($q) or die(mysql_error()); while($row = mysql_fetch_assoc($r)){ // for each ID in the table $id = $row['FacID']; // Short hand variable // Generate short hand variables for the check boxes $chkActive = isset($_POST[$id.'_active']) && $_POST[$id.'_active'] == 'on' ? true : false; $chkCoaching = isset($_POST[$id.'_coaching']) && $_POST[$id.'_coaching'] == 'on' ? 'T' : 'F'; $chkCounseling = isset($_POST[$id.'_counseling']) && $_POST[$id.'_counseling'] == 'on' ? 'T' : 'F'; $chkFacilitating = isset($_POST[$id.'_facilitating']) && $_POST[$id.'_facilitating'] == 'on' ? 'T' : 'F'; // At this point, chkActive is equal to true or false // And each of chkCoaching, chkCounseling, and chkFacilitating are // equal to 'T' or 'F' // Determine where to insert this ID into our SQL_IDs array if($chkActive){ $SQL_IDs['Active'][] = $id; }else{ $SQL_IDs['Inactive'][] = $id; } $SQL_IDs[$chkCoaching.$chkCounseling.$chkFacilitating][] = $id; } // Run our queries foreach($SQL_IDs as $key => $ids){ switch($key){ case 'Active': $sql = "Update `".F_TABLE."` Set Active = '1' WHERE FacID IN (" . implode(", ", $ids) . ")"; break; case 'Inactive': $sql = "Update `".F_TABLE."` Set Active = '0' WHERE FacID IN (" . implode(", ", $ids) . ")"; break; default: $sql = "Update `".F_TABLE."` Set Type=" . $TTable[$key] . " WHERE FacID " . "IN (" . implode(', ', $ids) . ")"; break; } // DEBUG -- print the sql for verification echo '<pre style="text-align: left;">' . print_r($sql, true) . '</pre>'; //mysql_query($sql) or die("ERROR: " . mysql_error()); } ?> (EDIT) I also noticed in your code a couple of your conditions you were setting $queries[$id][5] instead of $queries[$id][2]. I assume that was either an error on your part OR you were trying to add an 'AND' condition to your WHERE part. If you were trying to add an AND condition then my code is going to do the wrong thing; also, your syntax for the AND condition would be wrong anyways, which is why I assumed you made a typo. Also, I said my code doesn't decrease the amount of loops, I misspoke. It does decrease the amount of loops in the original code, but it still has to loop over every entry in the database. When I said it doesn't decrease the amount of loops I was referring to the fact that it still has to loop over all the database entries; that's the best I could achieve with the information given.
  24. Assuming I followed your code correctly, I made the following truth table: coaching | counseling | facilitating | TYPE ---------+------------+--------------+----- T | T | T | 7 T | T | F | 5 T | F | T | 4 T | F | F | 1 F | T | T | 6 F | T | F | 2 F | F | T | 3 F | F | F | # From the looks of the table, it doesn't look like you can solve this with bit-wise operations. I'll prove it to you: #1: The following row suggests that counseling would represent the second bit: 010 F | T | F | 2 #2: The following row suggests that coaching is the first bit: 001 T | F | F | 1 #3: If we ORed coaching and counseling when both were true, we should get: 011 -> 3 #4: In fact, we get: 101 -> 5 (CONTRADICTION) T | T | F | 5 K, I'll have a solution in a few.
×
×
  • 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.