Psycho
Moderators-
Posts
12,159 -
Joined
-
Last visited
-
Days Won
130
Everything posted by Psycho
-
Sorry, but your "question" is not clear. You say you have created the code needed to convert an integer to a hexadecimal value. Then you ask "do i need to write mutlitple if functions to check through the array". What are you doing with the array? I guess I will assume that the array is filled with integer values that you want converted to hexadecimal. Do you want those values repopulated back into the array or just echo'd to the page? Since you didn't provide the code you created for converting the value I can't tell you how to utilize it with your array (however, I'm guessing you created something that was not needed - I'm sure there is an easy way in PHP to do the conversion automatically). Without knowing the structure of your array I can't be sure, but you would probably wwant to do something like this foreach ($array as $intValue) { echo conversionFunction($intValue); }
-
Your code works fine for me. I used the code you provided and created a test.php file, then created a (users.db.php) file with the content you showed. The output I received when running the test php file is Id Username Password Permissions Last Logged In You should get an error if the file name or path are incorrect. Are you poistive you don't have two versions of users.db.php floating around? Try running just this code to ensure you are reading the file $users = file("users.db.php"); $lineno = 1; foreach ($users as $line) { $user = explode('|', $line); echo "Line $lineno: $line\n"; $lineno++; }
-
Now, this will most likely not affect your particular application as you are using it for data of birth, but just for educational purposes: That leap year logic is not correct. Leap years do not occur every 4 years - exactly. There are exceptions to that. A year is a leap year if it is divisiable by 4 AND if is NOT divisiable by 100, UNLESS it is also divisable by 400. So every '00 year is not a leap year unless it is also divisable by 400. The year 2000 was a leap year, but hte year 2100 will not be. But, since you are using this for DOBs, the logic of just using divisable by four would cover everything from 1901 to 2099.
-
There's a much easier way. Assuming the list of player names is $_SESSION['players'] it is a simple operation //Randomize the player names shuffle($_SESSION['players']); $maxTableSize = 10; //Change to any value you want $tableCount = ceil(count($_SESSION['players']) / $maxTableSize); //Assign each plaer to a table foreach ($_SESSION['players'] as $pnum => $player) { $tables[$pnum % $tableCount][] = $player; } That will result in a multidimensional array like this Array ( [0] => Array ( [0] => Player Name 25 [1] => Player Name 12 [2] => Player Name 5 [3] => Player Name 6 [4] => Player Name 9 [5] => Player Name 13 [6] => Player Name 4 [7] => Player Name 23 [8] => Player Name 2 ) [1] => Array ( [0] => Player Name 16 [1] => Player Name 10 [2] => Player Name 18 [3] => Player Name 11 [4] => Player Name 17 [5] => Player Name 8 [6] => Player Name 14 [7] => Player Name 15 ) [2] => Array ( [0] => Player Name 24 [1] => Player Name 7 [2] => Player Name 19 [3] => Player Name 1 [4] => Player Name 20 [5] => Player Name 22 [6] => Player Name 21 [7] => Player Name 3 ) )
-
Post Form Values to 2 Different External Sites
Psycho replied to ultrasound0000's topic in PHP Coding Help
I didn't read through that page, but it appears to be a function that allows you to post data to a page through the code. So, you would just need create a page that accepts the POSTed data, then rePOST the data by using that function twice (once for each external page to post the data to) -
If the user does not have JS enabled, the form will always be submitted. The form can't check if a true or false value is returned if JS is not enabled. Not sure I follow the last bit. Are you saying the server-side code is generating error messages to be displayed? If so, I would agree that is a good process. Based upon your request it appeared you wanted the JS to run on load of the page to display the error messages, which wouldn't make sense if the form was submitted with errors because the user did not have JS enabled. Again, it's your call. I'm just giving my two cents. Good luck.
-
Post Form Values to 2 Different External Sites
Psycho replied to ultrasound0000's topic in PHP Coding Help
OR, HTTP POST from PHP, without cURL http://netevil.org/blog/2006/nov/http-post-from-php-without-curl -
It's your call, but I would reate my server-side validation to output the page with the same error messages/states that the JavaScipt validation would do. Then you don't need to run the JS validation onload. Again, if you are running server-side validation to catch errors for users w/o JS, what would those users see in the way of error messages if you are relying on the JS to diplay the errors?
-
OK, I am assuming from your response that you have default code that creates the head and <BODY> tag for the page. It is only in the content of the page that you would *know* what page is being loaded? Well, that is easy enough to work around. You could simple insert this bit of code within the code that builds the form <script type="text/javascript"> window.onload = function() { checkForm(); } </script> But, I think this is a poor approach. JavaScript validation is a great tool to give the user some immediate feedback, but your pages should never totally rely upon JavaScript - especially for validation. I'm assuming you want to validate the page when it loads because some fields will already be populated. I can only think of that occuring if you have server-side validation and are redisplaying the form after server-side validation fails. Well, server-side validation should always be in place (in case user has JS turned off). But, if user has JS turned off and they submit invalid data, what would be the point of returning them to the form and trying to use JS to tell them their errors. You should use the server-side code to display the erros of any data that has been submitted.
-
[SOLVED] Need help how to use two submit buttons in the same form
Psycho replied to matrixrp's topic in PHP Coding Help
Well, I agree that you HAVE to check the username for uniqueness when the complete form data is ultimately submitted, but you *COULD* have another button to check the username. But, you would want to do so with AJAX - otherwise the user might enter data for the entire form and submit only to have the username checked. But, that gets more complex than just checking it on the complete form submission. If you go with only checking it on the complete form submission (which you have to do anyway) you will have a working solution. You can aways add a feature for the user to check for available usernames at a later time. -
Please mark thread as solved! Also, I wouldsuggest changing your query as follows $sql = "SELECT affiliate_code FROM affiliates WHERE affiliate_code='".$affiliate_code."'"; No need to query all fields in the table.
-
I'm pretty sure the file is already uploaded to a temporary location by the time your processing script begins to execute. The OP wants to avoid the upload process. From w3schools: $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server Another thought: It might be enough to just not include the enctype parameter for the form to ensure the file is not uploaded (not tested). Would probably want to test this on a few different browsers to be sure.
-
Create the form with an upload field and a hidden field. Then on submission of the form, using javascript, populate the hidden field with the value of the upload field and remove the upload field. Here's an example: <?php if(isset($_POST)) { $post = "Here are the posted values:<br />"; foreach($_POST as $name => $value) { $post .= "<b>Name:</b> $name<br /><b>Value: </b>$value<br /><br >\n"; } } ?> <html> <head> <script type="text/javascript"> function submission() { var uploadObj = document.getElementById('uploadFld'); var textObj = document.getElementById('file_name'); textObj.value = uploadObj.value; uploadObj.parentNode.removeChild(uploadObj); return true; } </script> </head> <body> <?php echo $post; ?> <form method="POST" onsubmit="return submission();"> Choose a file to upload: <input name="upload" id="uploadFld" type="file" onchange=""/><br /> File Path: <input type="hidden" name="file_name" id="file_name" value="" /><br /> <input type="submit" value="Upload File" /> </form> </body> </html>
-
The problem is the actions in the onmouseover and onclick triggers are not within quotes <?php echo "<tr class=\"{$class}\" onmouseover=\"this.style.cursor='pointer';\" onclick=\"location.href='esl-teaching-position.php?id={$row['submission_id']}';\">"; ?>
-
*** RussellReal extracts foot from mouth *** *** And then inserts directly up the rectum of mjdamato *** Grow up, it was just some good natured ribbing. Didn't mean to offend @Mark Baker: You could accomplish the same thing more efficiently using the same logic Sasa provided: function MROUND($num, $unit) { if ($unit==0) { return $num; } $multiplier = 1 / $unit; return round($num * $multiplier ) / $multiplier; }
-
*** RussellReal extracts foot from mouth ***
-
EDIT: Sasa beat me to it.
-
how do i put a var in a simple java cancel button ?
Psycho replied to jamesxg1's topic in PHP Coding Help
Not to be picky (well yes I do) that is JavaScript not Java. To answer your question I am assuming that $usID and $username are the PHP variables. If you are including that line above as it is displayed it won't work because PHP will not process it. PHP only processes code within the PHP opening and closing tags. Yo uwould need to do something like this: <input type="button" onClick="javascript:window.location='../main/Profile.php?usID=<?php echo $usID; ?>&username=<?php echo $username; ?>" class="button" value="Cancel" /> -
Putting your javascript inline like that is not recommended and makes your code unwieldly. Just make a function that you can reuse if needed <html> <head> <script type="text/javascript"> function displayField(fieldID, display) { document.getElementById(fieldID).style.display = (display) ? 'inline' : 'none'; } </script> </head> <body> <input name="checkbox_other" type="checkbox" class="text_background" id="checkbox_other" value="other" onclick="displayField('newClientLbl', this.checked)"> <label style="display:none" id="newClientLbl">Enter Your Client Type: <input type="text" name="newClient" class="text_background"></label> </body> </html>
-
Just a side note to start, it's typically good manners to address a person by their name rather than the type of code they posted Anyway, yes you can do anything with the selected values that you want! You can do something in real-time on the screen with JS or you can do something with it in PHP once you post the form. To do something real-time, just put an onchange event handler on the select list. Not sure what you mean by this statement Once the value is stored you can do whatever you want with it. If you are asking how you would utilize the variable in JS once you have stored it, that's simple. When creating any page where JS needs to utilized the saved value, just write it to the page as a JS variable echo "var foo = bar;"; Here's another example of the code showing how to do something once a value is selected. Note that depending on your ultimate use of all this, another solution would be to create both select lists on the page at the beginning and change the display propert accordingly. Not knowing your ultimate goal, I can't say which method would be more advantageous <html> <head> <script type="text/javascript"> units = new Array(); units['month'] = ['January','February','March','April','May']; units['week'] = ['Week 1','Week 2','Week 3', 'Week 4']; function changeUnits(unitName) { var options = units[unitName]; options.unshift('Select a '+unitName); changeSelect('units', options, options); document.getElementById('units').disabled = false; return; } function changeSelect(fieldID, newOptions, newValues) { selectField = document.getElementById(fieldID); selectField.options.length = 0; if (newValues && newOptions) { for (i=0; i<newValues.length; i++) { selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]); } } return; } function doSomething(selObj) { var output = ''; if (selObj.selectedIndex!=0) { var optValue = selObj.options[selObj.selectedIndex].value; var radioGrp = document.getElementById('testForm')['unitName']; var unit = (radioGrp[0].checked)?'month':'week'; output = 'You have selected the '+unit+' of '+optValue; } var outputDiv = document.getElementById('output'); outputDiv.innerHTML = output; return; } </script> </head> <body> <form name="testForm" id="testForm"> <input type="radio" name="unitName" value="month" onclick="changeUnits(this.value);"> Months<br> <input type="radio" name="unitName" value="week" onclick="changeUnits(this.value);"> Weeks<br><br> <select name="units" disabled="disabled" onchange="doSomething(this);"> <option>Select a Unit</option> </select> </form> <br /><br /><br /> <div id="output"></div> </body> </html>
-
[SOLVED] query boggs down my server and I cannot figure out why
Psycho replied to jakebur01's topic in PHP Coding Help
Hmm... Well, obviously I am not the expert in what you are working with and trying to accomplish (you are), but it just seems to me that this is being over-complicated. And what you just stated still doesn't seem to coincide with the code you had posted where you are updating fileds with their current values. a.$list =b.$list, The variable list will have the same value when that is parsed and the field will set itself to it's current value. I would expect to see something more like this a.$list1 =b.$list2, If this is a one time process, then just break it down into smaller chunks. If not, then you might want to rethink the process. -
NOt sure what you mean. Where is the word "on" coming from? I see no reason you can't do this with JS. <html> <head> <script type="text/javascript"> units = new Array(); units['months'] = ['January','February','March','April','May']; units['weeks'] = ['Week 1','Week 2','Week 3', 'Week 4']; function changeUnits(unitName) { values = units[unitName]; changeSelect('units', values, values); document.getElementById('units').disabled = false; return; } function changeSelect(fieldID, newValues, newOptions) { selectField = document.getElementById(fieldID); selectField.options.length = 0; if (newValues && newOptions) { for (i=0; i<newValues.length; i++) { selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]); } } } </script> </head> <body> <input type="radio" name="unitName" value="months" onclick="changeUnits(this.value);"> Months<br> <input type="radio" name="unitName" value="weeks" onclick="changeUnits(this.value);"> Weeks<br><br> <select name="units" disabled="disabled"> <option>Select a Unit</option> </select> </body> </html>
-
[SOLVED] query boggs down my server and I cannot figure out why
Psycho replied to jakebur01's topic in PHP Coding Help
Since you have the table name as a variable I assume you are running this query on multiple tables. Are you running this query in a loop to update all the tables at once? Is there a particular reason you have multiple tables to capture all the same data? Looking at your original query, it makes no sense to me if I am reading it right. You define the same table as 'a' and 'b' and then set column values in table a to the corresponding column values in table b. But, since they are the same table the end result would be no change! The WHERE clause is equally perplexing since this condition would never be true WHERE LEFT(b.col2, CHAR_LENGTH(b.col2)-2) = a.col2 a.col2 & b.col2 will be the same value, so the value of b.col2 minus two characters would never equal a.col2 (unless the values were empty to begin with). The code you posted in your second post would be slow as well due to the looping queries you have. And it has additional problems, such as not identifying the table name in the 2nd query. If the 2nd query is being run on the same table as the first query, then you will end up with the same results as before - nothing. Because you are setting a field to its current value. If you are updating a different table, then it is still appears problematic, as it would only be copying the same values from one table into another. If these records are related then you should just enter a foreign key into the child record referencing the parent record. -
I'm not that great at regular expressions, so I'm not sure if this would work in 100% of cases, but it works with the example you provided: $string = "1221344136613"; preg_match_all ( '/1{0,1}(.*?)(13)/', $string, $matches ); print_r($matches[1]); Output [0] => 22 [1] => 44 [2] => 66
-
Please mark topic as solved