Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Call To Undefined Function Themeheader()
Psycho replied to jmeyers's topic in PHP Installation and Configuration
There error is self explanatory. You are calling a function called themeheader() and the function has not been defined. When a page loads there can be any number of include files and even the file above could have been (and probably was) included from a different file. You need to figure our in which file themeheader() is defined and figure out where that file should be included. So, look at the include files in that script above first. Then you might have to trace from the page that the user first accesses to the script above. Also, as a quick test, I notice that all of your include()'s have an ampersand in front of them which would suppress an error. So, it could be that one or more of those include files have been moved or deleted (and one of them is where the function was defined). Remove those ampersands and see if any errors are reported. -
Hmm, are you creating an array of the values and concatenating them after the loop or are you overwriting the a "value" variable on each iteration of the loop and only running the query on that value? Echo your query to the page.
- 11 replies
-
- array
- multiple arrays
-
(and 1 more)
Tagged with:
-
I guess it's been too long since I've done much Javascript. For some reason IE is not seeing the variable 'urls', the string with all the base urls, as a global variable. One easy fic is to just move the declaration of urls inside the function. function updateURLs(numbers) { var urls = ''; urls += "http://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_s.jpg\n"; // . . . include all other base URLS var numAry = numbers.split(','); var numLen = numAry.length var output = ''; var urlSet; for(var i=0; i<numLen; i++) { var num = numAry[i].replace(/^\s+|[^\d]*|\s+$/g, ''); if(num.length < 4 || num.length > 9) { //Error condition, don't use. Add error handling } else { urlSet = urls.replace(/\[yyyyyy\]/g, num); urlSet = urlSet.replace(/\[xxxxxx\]/g, num.substr(0, num.length-3)+'000'); output += urlSet + '\n'; } } document.getElementById('output').value = output; }
-
Bingo! Don't feel too bad. I see people that do similar things a lot - especially when create a string concatenated from literal strings and variable - but if the value will end in a variable they always seem to tack on a . "" $query = "SELECT * FROM table WHERE id = " . $id . ""; instead of just $query = "SELECT * FROM table WHERE id = " . $id; or my preference $query = "SELECT * FROM table WHERE id = {$id}";
-
Here is a quick and dirty example <html> <head> <script type="text/javascript"> function setOtherInput(colorSelect) { visibileState = (colorSelect.value==false) ? 'visible' : 'hidden'; document.getElementById('color_input').style.visibility = visibileState; } </script> </head> <body> Select a color: <select name="color" id="color" onchange="setOtherInput(this);"> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> <option value="yello">Yellow</option> <option value="0">Other</option> </select><br> <div id="color_input" style="visibility:hidden">Other color: <input type="text" name="other_color" /></div> </body> </html>
-
<!DOCTYPE html> <html> <head> <title>Purge List Generator</title> <style> hr {color:sienna;} p {margin-left:20px;} body { background-image:url('bg1.jpg'); background-repeat:repeat-x; } </style> <script type="text/javascript"> var reader = new FileReader(); function rip(e) { var out=(e && e.target && e.target.result) || output.value ; var reps=txtReps.value.split(/\s*,\s*/); output.value= out.split("\n").map(function(a){ return a .split("xxxxxx").join(reps[0]) .split("zzzzzz").join(reps[1]); }).join("\n"); } function readText(that) { if(that.files && that.files[0]){ var reader = new FileReader(); reader.onload = rip; reader.readAsText(that.files[0]); }//end if html5 filelist support } String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');}; var urls = ''; urls += "http://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_s.jpg\n"; urls += "https://images.mysite.com/productImages/_[xxxxxx]/FF_[yyyyyy]_s.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/ff_[yyyyyy]_xl.jpg&w=68\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/ff_[yyyyyy]_xl.jpg&w=68\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=90\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=108\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=140\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=148\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=160\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=165\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=165\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=180\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/FF_[yyyyyy]_xl.jpg&w=200\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/ff_[yyyyyy]_xl.jpg&w=250\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/ff_[yyyyyy]_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]%2fFF_[yyyyyy]_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=%2fproductImages%2f_[xxxxxx]%2fff_[yyyyyy]_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/ff_[yyyyyy]_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]%2fFF_[yyyyyy]_xl.jpg&w=600\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=%2fproductImages%2f_[xxxxxx]%2fff_[yyyyyy]_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT1_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT2_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT2_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT3_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT3_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT4_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT4_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT5_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT5_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT6_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT6_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT7_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT7_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT8_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT8_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT9_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT9_xl.jpg&w=600\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_xl.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_l.jpg\n"; urls += "http://images.mysite.com/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_tb.jpg\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_xl.jpg&w=35\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_xl.jpg&w=60\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_xl.jpg&w=400\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productimages/_[xxxxxx]/altimages/FF_[yyyyyy]ALT10_xl.jpg&w=500\n"; urls += "http://images.mysite.com/FFImage/thumb.aspx?i=/productImages/_[xxxxxx]/altImages/FF_[yyyyyy]ALT10_xl.jpg&w=600\n"; function updateURLs(numbers) { var numAry = numbers.split(','); var numLen = numAry.length var output = ''; var urlSet; for(var i=0; i<numLen; i++) { var num = numAry[i].replace(/^\s+|[^\d]*|\s+$/g, ''); if(num.length < 4 || num.length > 9) { //Error condition, don't use. Add error handling } else { urlSet = urls.replace(/\[yyyyyy\]/g, num); urlSet = urlSet.replace(/\[xxxxxx\]/g, num.substr(0, num.length-3)+'000'); output += urlSet + '\n'; } } document.getElementById('output').value = output; } </script> </head> <body> <center> <input type="file" onchange='readText(this)' /><br /> <textarea rows=5 cols=84 id="txtReps" onblur="updateURLs(this.value);">123456</textarea><br /> <button onclick="rip()">run script</button> <button onclick="output.value=output.defaultValue;">reset</button><br /> <textarea rows=30 cols=130 id="output"></textarea><br> </center> </body> </html>
-
So, you are sending the explicit $_POST[fieldname] variables to the function. So, as stated before you will need to define the index value to be the same for each "set" of field or else they will not be grouped together. Then to solve your problem you need to ensure that you are checking if each field has a value. If it doesn't you need to set an appropriate value for the INSERT query. So, let's say that for the first set of fields the 'home_pens' checkbox was not set. In your insert query you are trying to insert a value for that field for that record. Since the user did not check that checkbox the field doesn't even exist in the post data. So, you need to put 'something' for that value in the insert query. In fact you should validate/sanitize all of the data. Here is an example: foreach(array_keys($fixture_id) as $n) { $id = intval($fixture_id[$n]); $htGoals = isset($ht_goals[$n]) ? intval($ht_goals[$n]) : 0; $atGoals = isset($at_goals[$n]) ? intval($at_goals[$n]) : 0; $etVal = isset($et[$n]) ? intval($et[$n]) : 0; $hPens = isset($h_pens[$n]) ? intval($h_pens[$n]) : 0; $post= isset($postponed[$n]) ? intval($postponed[$n]) : 0; $valuesAry[] = "($id, $htGoals, $atGoals,$etVal, $hPens, $post)"; }
- 11 replies
-
- array
- multiple arrays
-
(and 1 more)
Tagged with:
-
I understand what you are trying to achieve, but reading your questions/comments is confusing. I think you are making this way more complicated than it needs to be. I'll provide a general description of how you can accomplish what you want. 1. In the database you want to have the primary ID of the records and a separate field for the order (it seems you already have this). 2. When creating your form you will create a field to change the order for each record. The NAME of these fields should be an array which uses the primary id of the record as the index of the field name. Example <input type="text" name="order[3]" value="1"> Record id#3, first in order <input type="text" name="order[2]" value="2">Record id#2, second in order <input type="text" name="order[5]" value="3">Record id#5, third in order <input type="text" name="order[4]" value="4">Record id#4, fourth in order 3. When the user POSTS the form you will iterate over the array $_POST['order'] and verify that all the values are appropriate and then update the value for each field appropriately. Here is some sample code foreach($_POST['order'] as $id +> $order) { $id = intval($id); $order = intval($order); $query = "UPDATE table SET order = $order WHERE id = $id"; $resutl = mysql_query($query) or die(mysql_error()); } A few notes: 1. You should really never run queries in a loop. But, the format for creating an UPDATE query with multiple records being updated with different data is a little complicated and I'm too lazy to look up the format and doing this for a relatively small number of records shouldn't be a bug issue. But, I suggest you look into the process of creating a single query to update all the records rather than doing each individually in the loop. 2. The logic above does not take into consideration any verification that the order values submitted make sense. So a user could give multiple records the same order value or no value (no value would become a 0). So, if you want to provide some error/warning handling to ensure that all records are given a unique order value and that they are sequential you would want to do that before doing the update.
-
Well, one glaring problem I see is that some of those fields are checkboxes. Based on my understanding you have "groups" of fields and you are trying to associate the fields based upon their index. The problem is that checkboxes are not passed in the POST data if they are not checked. That means if the "home_pens" checkbox is not checked for group 1 or group 2, then the group 3 checkbox will have an index of 0 and be associated with the textboxes from group 1. You will want to manually create indexes for the array field names in your form. Just create a variable (e.g. $i) and set it to 0 before the loop, then increment it at the end of each iteration of the loop. Then use it in the form fields like this echo "<td><input name="home_pens[$i]" type="checkbox" value="'.$row['home_id'].'" /></td>"; Aside from that you still haven't shown how you are creating the variables from the POST data that are then passed to the function. As I stated previously the values don't exist or are empty. Where is the code that calls the function submitResults() and, more importantly, where are you creating the variables you send to that function.
- 11 replies
-
- array
- multiple arrays
-
(and 1 more)
Tagged with:
-
Wow, you could have saved yourself and us a ton of time if you had stated that the images were associated with the restaurant names in a database. I assume that you will need to update the database record with the new name since 1) it is possible, however unlikely, that two restaurants could have the same name and/or you might want to support multiple pictures at some point. And 2) You will need to replace some characters in the name to prevent problems with the file. I would also expect that you will be updating the upload script to name the files based upon the restaurant name too. So this script should be used as a one time operation to update the existing images. So, you want to do two things. 1) Create a function to generate the file name based upon the restaurant name. You will use this in your current upload script and for the batch update script for current images. 2) Create the batch update script to get the data from the database and update current images and the update the DB records with the new name.
-
I find it amusing that people will expand the parameters allowed but then only give examples using the values that are "easy". You say that the input can be one to nine digits. But, all your examples show where the second permutation of the input has the last three digits replaced by zeros. Ok, so what happens if the user inputs a number that is one to three digits in length? 1234 replaces "xxxxxx and zzzzzz" with 1234 and 1000 123 replaces "xxxxxx and zzzzzz" with ??? and ??? 12 replaces "xxxxxx and zzzzzz" with ??? and ??? 1 replaces "xxxxxx and zzzzzz" with ??? and ???
-
In your foreach() loop to create the "values" the arrays foreach(array_keys($fixture_id) as $n) { $valuesAry[] = "($fixture_id[$n], $ht_goals[$n], $at_goals[$n], $et[$n], $h_pens[$n], $postponed[$n])"; } The variables $ht_goals[$n], $at_goals[$n], $et[$n], $h_pens[$n], and $postponed[$n] do not exist or do not have a value. How are these arrays generated? It may help to show the form.
- 11 replies
-
- array
- multiple arrays
-
(and 1 more)
Tagged with:
-
<!DOCTYPE html> <html> <head> <title>file reps</title> <script type="text/javascript"> var reader = new FileReader(); function rip(e) { var out=(e && e.target && e.target.result) || output.value ; var reps=txtReps.value.split(/\s*,\s*/); output.value= out.split("\n").map(function(a){ return a .split("xxxxxx").join(reps[0]) .split("zzzzzz").join(reps[1]); }).join("\n"); } function readText(that) { if(that.files && that.files[0]){ var reader = new FileReader(); reader.onload = rip; reader.readAsText(that.files[0]); }//end if html5 filelist support } String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');}; var urls = new Array(); urls[0] = "http://www.mysite.com/file/folder/blah/[xxxxxx]/_something_else here/[yyyyyy]/image250"; urls[1] = "http://www.mysite.com/file/folder/blah/[xxxxxx]/_something_else here/[yyyyyy]/image500"; urls[2] = "http://www.mysite.com/file/folder/blah/[xxxxxx]/_something_else here/[yyyyyy]/image800"; urls[3] = "http://www.mysite.com/file/folder/blah/[xxxxxx]/_something_else here/[yyyyyy]/image1000"; function updateURLs(numbers) { var output = ''; var numAry = numbers.split(','); var numLen = numAry.length var urlLen = urls.length; for(var i=0; i<numLen; i++) { var num = numAry[i].replace(/^\s+|[^\d]*|\s+$/g, ''); if(num.length != 6) { //Error condition, don't use. Add error handling } else { //add number replacement to each URL for(j=0; j<urlLen; j++) { url = urls[j].replace("[xxxxxx]", num); url = url.replace("[yyyyyy]", num.substr(0, 3)+'000'); output += url + '\n'; } //Add line break between each section output += '\n'; } } document.getElementById('output').value = output; } </script> </head> <body style="zoom: 1.5"> <center> <input type="file" onchange='readText(this)' /><br /> <textarea rows=10 cols=84 id="txtReps" onblur="updateURLs(this.value);">123456, 123000</textarea><br /> <button onclick="rip()">run script</button> <button onclick="output.value=output.defaultValue;">reset</button><br /> <textarea rows=10 cols=84 id="output"></textarea> </center> </body> </html>
-
I'm still at a loss as to how you would determine what an image should be renamed to. You give the example of renaming img_003452.jpg to my-restaurant.jpg. How would that be determined? In other words, why wouldn't that image be renamed to some-other-restaurant.jpg?
-
$sql = "SELECT user_id, fname, lname FROM registration"; $result = mysql_query($sql); $selected_id = isset($_POST['user_id']) ? intval($_POST['user_id']) : false; $who = ''; $options = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['user_id']) { $who = "{$row['fname']} {$row['lname']}"; $selected = ' selected="selected"'; } else { $selected = ''; } $options .= "<option value=\"{$row['user_id']}\"{$selected}>{$row['fname']} {$row['lname']}</option>\n"; }
-
I'll add a clarification to DavidAM's spot-on statements. Even when you are using AJAX, the validation for something such as verifying if a username is taken still takes place "on the server", and it is important to revalidate when the form is posted. The username could have been taken between the time the validation was done using AJAX and the time the user ultimately submitted the form.
-
The solution is in the logic of displaying the results - not the query. You need to create a variable to track when the location changes and only display the location when is changes. Also, in my opinion, breaking in and out of PHP only makes the code harder to maintain. I'm also curious why the results are being generated from an array. That would indicate that you are looping through the query to put the results into an array and THEN using the array to generate the output. That is wasteful. You should just create the output when processing the results of the query. Lastly, you should use proper JOINs on your query, else it is going to be difficult to get more advanced data. $query = "SELECT sum(order.quantity) as quantity, sum(order.ordervalue) as value, products.id, products.name locations.location, locations.locationid FROM order JOIN products ON order.prodid = products.id JOIN locations ON order.deliverylocationid = locations.locationid WHERE order.status = 'open' GROUP BY order.deliverylocationid, order.prodid ORDER BY locations.location asc;"; $result = mysql_query($query) or die(mysql_error()); //Create variable to track when location changes $current_location_id = ''; while($row = mysql_fetch_assoc($result)) { //Check if city is different thatn last record if($current_location_id != $row['locationid']) { //Display City $city_display = anchor("admin/reports/SpecificLocation/{$row['locationid']}", $row['location']); echo "<tr><td colspan='4'>{$city_display}</td></tr>\n"; $current_location_id = $row['locationid']; } //Display product total echo "<tr>\n"; echo "<td width='60' align='center'>{$row['id']}</td>\n"; echo "<td width='60' align='center'>{$row['quantity']}</td>\n"; echo "<td width='250'>{$row['name']}</td>\n"; echo "<td width='150'>{$row['value']}</td>\n"; echo "</tr>\n"; }
-
I must be misunderstanding what you really want. You can't name them all the same name. Are you wanting to name them something like: my-restaurant_0.jpg, my-restaurant_1.jpg, my-restaurant_2.jpg, etc.? Or, are these images for different pages and each one will have a unique name? If you are wanting them all to be the same name with a different number associated with them, then just use Windows to rename them. I think you need Vista or higher for this. Just select all the images, then right-click and select rename. Windows will rename all of them and append a number after each one. However, if you want all the images to have different names I can't provide a solution because you haven't provided any information on how you are going to relate the image to the page. I.e. what logic would be used to know img_04352.jpg should be renamed to my-restaurant.jpg
-
Then you should provide that information up front. There are a lot of people that are new to coding that come to this forum and, many times, they are asking for a solution that is a bad one and will set a bad precedent for their learning. So, when responding to requests I feel obligated to prevent propagating bad habits before they start. But, what you said still makes no sense. There should be nothing in the HTML code for the product and/or price other than an ID for the product and the quantity. But, no matter, you think you know what you are doing so I'll give you a potential solution. Just give me a URL to the site so I can go and purchase whatever they are selling and I can change the price to $0.01 Use an onchange trigger to take the value of the select field as you currently have it and split() the string based upon the dash. If any product names can contain a dash then you would have to use logic to split it only at the last dash. Then take those two values and populate into the hidden fields. <html> <head> <script type="text/javascript"> function populateNamePrice(value) { var name, price; if(value=='') { document.getElementById('name').value = ''; document.getElementById('price').value = ''; return } var value_parts = value.split(' - '); document.getElementById('name').value = value_parts[0]; document.getElementById('price').value = value_parts[1]; return; } </script> </head> <body> Select a product: <select name="product" id="product" onchange="populateNamePrice(this.value);"> <option value="">-- Select a Product --</option> <option value="Product 1 - 1.00">Product 1 - 1.00</option> <option value="Product 2 - 2.00">Product 2 - 2.00</option> <option value="Product 3 - 3.00">Product 3 - 3.00</option> <option value="Product 4 - 4.00">Product 4 - 4.00</option> <option value="Product 5 - 5.00">Product 5 - 5.00</option> <option value="Product 6 - 6.00">Product 6 - 6.00</option> </select> <br><br> Name: <input type="text" name="id" id="name" readonly="readonly"><br> Price: <input type="text" name="price" id="price" readonly="readonly"><br> </body> </html>
-
How Do I Check If A Row Exists In My Form Validation Rules?
Psycho replied to RalphLeMouf's topic in Frameworks
I agree with you on the basic statement of not manipulating input - except for trimming. I advocate always trimming input, unless there is a valid reason not to. And, of course, passwords are one of those exceptions. But, for "normal" inputs: username, emails, person name, address, phone, etc. leading and trailing spaces wound not make sense and the space bar is likely pressed as a mistake in those instance ( ). There isn't anything inherently wrong with not trimming, but that would require adding additional validation logic since you wouldn't want an input of nothing but spaces for things such as names, addresses, etc. -
Savings Coumpound Interest (With Monthly Contribultion)
Psycho replied to Skylight_lady's topic in PHP Coding Help
I don't think you understand how interest is calculated. The formulas you just posted are NOT correct. Interest is not calculated at the end of the year. It is commonly calculated each month, also known as the compounding period. So, if the interest rate is 3% and there are 12 compounding periods for the year, the bank will calculate the interest each month using 1/12th of the interest rate - .25%. Using the formula you have above you are applying the total interest at the end of the year. If that was the case you could simply make a huge deposit on Dec. 30th of each year and get a years worth of interest on it. By the same token, if you have $10,000 in the bank all year and then withdrew it on Dec. 30th you wouldn't get any interest. That is why interest is calculated monthly (typically). But, I think banks actually calculate the interest on the average daily balance. That is why it is important to know WHEN the monthly contribution is added. If it is added at the beginning or the end of the month it will affect the interest amount. The formulas you just posted would only be "partially" correct if the compounding period was yearly - which I have never seen. Calculating the interest for a year would look more like this when written out in long form: Month1Balance = (StartBalance + MonthlyAmount) * InterestRate Month2Balance = (Month1Balance + MonthlyAmount) * InterestRate Month3Balance = (Month2Balance + MonthlyAmount) * InterestRate etc. . . . But, because of average daily balance is what I think is really used, that would be the case if the monthly contribution is added right after the interest calculation each month. -
You can do that through the query, but it is easier, in my opinion, to just do that through the display logic $position = 0; while($row = mysql_fetch_assoc($result)) { $position++; //Use this value as the number to the left of the player name //Code to display the record follows } The image you linked to shows the records sorted by best score. Since you don't show the date, there is no way to determine if it is sorting by date as you want. Do your records have a date field? If so, use that. Otherwise you could use the ID field IF that is an auto-increment field AND you only create records and do not edit them. If you don't think the records are in the appropriate order provide: 1. A similar image as you posted, but add the ID and/or date field that you are using for sorting 2. The actual query that you are currently using.
-
I would suggest a different approach. Instead of submitting a default value into the database, go ahead and insert a null or empty value. THEN, when selecting records and displaying to a page implement logic to show the message if the value is empty. So, the logic you have on the script to INSERT the records would stay the same, respective to the solution you want. But, you have some gaps in the logic for checking that the values are actually valid and exist. Then on the script(s) to display the values you can do one of two things: 1. Modify the SELECT query to set the default message in the results where the value is null/empty SELECT field1, field2, IF(image<>'', image, 'default_image.jpg') as image_src FROM table - or - 2. Implement logic in the PHP code to use the default message in the results where the value is empty while($row = mysql_fetch_assoc($result)) { $image = ($row['image'] != '') ? $row['image'] : 'default_image.jpg'; }
-
First off, if you have a Javascript issue post the HTML source code - not the PHP code that creates the HTML. It is difficult to read the PHP and then in your head convert it to what the HTML will be, then determine what the Javascript is doing. Second, I agree completely with Xaotique. It usually makes no sense to use JS to auto-populate hidden fields since you can (and should) do that determination on the server. What is worse is that you appear to be populating an amount field. If this was for a shopping cart, it would be very easy for a user to override the value you set in that hidden field to change the price of the item. However, if you were using the logic to populate some read-only fields so the user can see the price or to auto-populate some fields you want the user to edit that would be fine. But, what it appears you are trying to use it for would open a gigantic hole for a malicious user. You are better off just having the select list and using the ID of the product as the value. Then pass that when the user submits to get the current price and do any calculations on the server.
-
Savings Coumpound Interest (With Monthly Contribultion)
Psycho replied to Skylight_lady's topic in PHP Coding Help
Well, you're not going to get exactly the same without knowing their formula. But, using the formulas at this site, I was able to create a formula that gets a result within about a dollar difference from the site you linked using different combinations of values. The problem is determining exactly when and how they calculate the interest and when they are calculating when the monthly contribution is made. Those determinations will change the interest calculations. $principle = 5000; $monthly_amt = 200; $years = 6; $rate = 3.5; $periods_per_year = 12; $periods = $years * $periods_per_year; $interest = $rate / 100 / $periods_per_year; $future_value = (pow(( 1 + $interest), $periods) * $principle) + ( $monthly_amt * ( ( pow( (1 + $interest), $periods) - 1) / $interest ) ); echo "Start: $ $principle<br>\n"; echo "Monthly: $ $monthly_amt<br>\n"; echo "Years: $years<br>\n"; echo "Rate: $rate %<br><br>\n"; echo "Total: $ $future_value<br>\n";