-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
No problem, glad to help!
-
Does the form need to submit back to the server...or does everything that needs to happen take place in Javascript? If the form data doesn't need to go back to the server for processing, try moving the "return false" part after the call to castMyVote(). <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0]); return false;"><img src="images/vote_button.gif"></a> If that doesn't work, you may need to incorporate the "return false;" into the castMyVote() function.
-
I think the problem comes from the Javascript code below: <a href="#" onclick="castMyVote(<?php echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a> Try changing the document.forms part to: document.forms[1] As a side note, I would recommend that you avoid using $_SERVER['PHP_SELF'] as the form action. For more information, see: http://seancoates.com/blogs/xss-woes
-
If an error is found, is there any reason to continue processing the numbers? If not, you could end the foreach loop with break: http://php.net/manua...tures.break.php The break would go into the else portion with the error message.
-
Isn't that what you want? "03443" and "23432" are both 5-digit numbers which don't meet your criteria.
-
Note that is_numeric() will accept values like "1e4" and "9.1". My current preference for checking numbers is ctype_digit(): http://www.php.net/m...ctype-digit.php Does the number have to be four digits? Could "0322" be entered as "322"?
-
Do you have any code for processing the form? As floridaflatlander suggested, you should be able to break apart the member code(s) with explode(): http://php.net/manua...ion.explode.php The array returned by the explode() function can then be processed with a foreach loop. Within the loop, you'll want to remove any leading/trailing space with trim(): http://us3.php.net/m...nction.trim.php ...and check to make sure the member codes are numbers and are four digits or less. If any member code doesn't meet the criteria, send them back to the form and have the user fix the error(s).
-
You could look into using explode() to break apart the data for processing: http://php.net/manua...ion.explode.php
-
Submit Form - Error/success Message On Index File
cyberRobot replied to hahaitwork's topic in PHP Coding Help
To execute PHP code, a request needs to be sent to the server. The same page can be called, but it needs to be reloaded. -
It's difficult to tell what you're looking for. Do you have any code? If not, I would recommend that you start with one dropdown box. Posting that code would make it easier for us to help you with incorporating additional dropdown menus.
-
That would be another test. If the array created by explode contains two items, you have what you need. If it has more, check if the first one is "www".
-
If the value needs to contain a # symbol, you could encode it: <?php print '<a href="localhost.php/test.php?say=' . urlencode('#hello') . '">Test</a>'; ?>
-
Couldn't you explode the value as mentioned to get the TLD. Then just test if the first part contains "www"?
-
For the calendar input, you could look at jQuery's Datepicker: http://jqueryui.com/datepicker/ To run a script on a regular basis, have a look at "cron jobs". https://www.google.com/search?q=cron+job
-
Are you okay with the function blocking potentially valid entries? Here are some examples of invalid entries: Conan O'Brien Dan "the Man" Ben & Jerry
-
Dynamically Combine Arrays With Array_Intersect()
cyberRobot replied to cyberRobot's topic in PHP Coding Help
Thanks for all the responses. I forgot all about looking into kicken suggestion. Thanks for showing me an implementation ManiacDan. I haven't totally wrapped my mind around what's going on, but the code looks much cleaner than mine. -
Dynamically Combine Arrays With Array_Intersect()
cyberRobot replied to cyberRobot's topic in PHP Coding Help
Just to clarify, there isn't a cleaner way of doing this without a bunch of if statements? If so, I may be better off with running the query... For reference, this is basically what I would be looking at: <?php //IF FIRST AND SECOND ARRAY CONTAIN IDS, FIND THE INTERSECT if(!empty($array1) && !empty($array2)) { $matchingIDs = array_intersect($array1, $array2); //ELSE...STORE MATCHES SO FAR } else { if(!empty($array1)) { $matchingIDs = $array1; } elseif(!empty($array2)) { $matchingIDs = $array2; } else { $matchingIDs = array(); } } //IF THE MATCHING IDS SO FAR AND THE THRID ARRAY CONTAIN IDS, FIND THE INTERSECT if(!empty($matchingIDs) && !empty($array3)) { $matchingIDs = array_intersect($matchingIDs, $array3); //ELSE...UPDATE MATCHES } else { if(!empty($array3)) { $matchingIDs = $array3; } } ?> -
Dynamically Combine Arrays With Array_Intersect()
cyberRobot replied to cyberRobot's topic in PHP Coding Help
If $array1, $array2, $array3 are empty, I want to ignore that array. Note that the reason an array would be empty is because a user chose an option which results in that array containing every ID from the database. Instead of running a query to get everything, I want to ignore that array. -
Dynamically Combine Arrays With Array_Intersect()
cyberRobot replied to cyberRobot's topic in PHP Coding Help
Here's a quick code sample: <?php $array1 = array(1, 2, 3, 4, 5, 6, 7, ; $array2 = array(2, 3, 5, 7); $array3 = array(1, 2, 3, 7, 9); $matchingIDs = array_intersect($array1, $array2, $array3); print_r($matchingIDs); ?> This gives me a list of IDs which appear in all three arrays: Array ( [1] => 2 [2] => 3 [6] => 7 ) If one of the arrays is empty, however, the result set is also empty. <?php $array1 = array(1, 2, 3, 4, 5, 6, 7, ; $array2 = array(); $array3 = array(1, 2, 3, 7, 9); ?> -
I’m using array_intersect() to combine three arrays. $matchingIDs = array_intersect($array1, $array2, $array3); Everything works until one of the arrays is empty. Is there a way to dynamically feed arrays to the function? I could use several if statements and array_intersect() calls, but it seems like there should be a better way.
-
It looks like you're getting the data twice: <?php $get = mysql_fetch_assoc($nav); //... while($get = mysql_fetch_assoc($nav)){ //... ?> So basically the first entry is ignored.
-
Also, this might be a silly question, but did you establish a connection to the MySQL database?
-
Have you checked if the variables contain values you would expect? For example, you said the code doesn't display anything...does $num indicate results were found in the database?
-
Have you tried turning on all errors and warnings? <?php error_reporting(E_ALL); ini_set('display_errors', 1); //...your code goes after this point ?>