Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by Sepodati

  1. You also have to change how you loop through the results. The key of prodCategories and orderp being the same is what links them. I think like this... foreach($cats as $i=>$thecatx) { //$thecatx = $cats[$i]; $orderx = $orderp[$i]; $catCategory = "INSERT INTO category_assoc (prod_id, cat_id, p_order) VALUES ('$lastID', '$thecatx', '$orderx')"; $wpdb->query($catCategory); }
  2. That would work, but you'd have to change how you reference $cat inside the for() loop. Or you could just keep a counter and output it's value in the prodCategories[] and orderp[] brackets, like below: $i = 0; foreach($cats as $cat) { ?> <tr> <td><?php echo $cat['cat_name'];?></td> <td> <input type='checkbox' name='prodCategories[<?=$i?>]' value='<?php echo $cat['cat_id']; ?>' <?php if($editProduct) echo $prod->isCheckSelected($cat['cat_id'], $vals['prod_id']);?>/> <?php if($editProduct) echo $prod->gettheOrder($cat['cat_id'], $vals['prod_id']); ?> <input type='hidden' name='orderp[<?=$i++?>]' value='<?php echo $prod->gettheOrder($cat['cat_id'], $vals['prod_id']);?>' /> </td> </tr> <?php }
  3. I don't know... why are you doing that?
  4. I think if you reversed that to start with group3 and go down to group1, that would match the OP's intent. Does unsetting values of an array you're currently looping through with foreach() create any side effects?
  5. You have to escape the encrypted value, for it to be put in a SQL query safely. Escaping before encrypting doesn't help, as the encryption process could create characters that need to themselves be escaped. Switch to using prepared statements, though, and that'll take care of the escaping for you.
  6. <tr> <td>USA Guitars</td> <td><input type='checkbox' name='prodCategories[]' value='3' checked/> <input type="hidden" name="orderp[]" value='2'/> </td> </tr> <tr> <td>Guitars</td> <td><input type='checkbox' name='prodCategories[]' value='36' checked /> <input type="hidden" name="orderp[]" value='5'/> </td> </tr> Given that code, for example, with only the second checkbox checked, you'll have $_REQUEST['prodCategories'] = array(36) and $_REQUEST['orderp'] = array(2,5) there's no way to relate $_REQUEST['prodCategories'][0] to $_REQUEST['orderp'][1], which is what I assume you want. Create your code like this, instead: <tr> <td>USA Guitars</td> <td><input type='checkbox' name='prodCategories[0]' value='3' checked/> <input type="hidden" name="orderp[0]" value='2'/> </td> </tr> <tr> <td>Guitars</td> <td><input type='checkbox' name='prodCategories[1]' value='36' checked /> <input type="hidden" name="orderp[1]" value='5'/> </td> </tr> And now you have $_REQUEST['prodCategories'] = array(1=>36) and $_REQUEST['orderp'] = array(0=>2,1=>5) where $_REQUEST['prodCategories'][1] and $_REQUEST['orderp'][1] are now related elements.
  7. Checkbox values are only sent if the box is checked. I think the problem you're having is that the checkbox array is (33,50) for the two boxes checked (for example) while the hidden elements are coming across as (1,2,3,4,5). Now cat[x] and orderp[x] do not align. I would build your form with explicit keys in the element names. prodcat[0], prodcat[1], etc. instead of just []. Then you'll have cat(2=>33,4=>50) and orderp(1,2,3,4,5) where cat[2] and orderp[2] are now aligned. You can use a foreach() to loop through the cat[] values, find orderp[$key] corresponding to it, and then build your query.
  8. 'group3' => string '' (length=3) Why does an empty string have a length of 3? If you're going to compare two strings, it doesn't make sense to run one of them through mysqli_real_escape_string() first, does it? Now the string is altered, potentially. You should only use that function (if it's even supposed to be used at all) when you're preparing data for a database query.
  9. Oh, I was just going for the joke, mostly. I'd use in_array() with a set list. Unless I'm missing something, though. <?php $value = 'Foo'; if($value != 'Public' && $value != 'Executive') { echo 'Invalid value!'; } else { echo 'All good'; } ?>
  10. I'll get you started. fopen()
  11. there are only two conditions and that will NEVER change, though, right? right? we all know that...
  12. The logic is messed up here: elseif ($_POST['boardsession'] != 'Public' || $_POST['boardsession'] != 'Executive') When the value is 'Public' this condition ends up as ( False || True ) and hence evaluates to TRUE. You end up with (True||False) when it's 'Executive' and still evals to TRUE.
  13. It may be executable, but is it executable by the user PHP (really Apache) runs as? Typically www-data. And does that user have access to that directory?
  14. Well, think about it. If the image is defined by the data "abcdef" and you output "abcdef\n\n", well, you haven't output the right bits for that image, have you. You've changed it by adding extra bits on the end.
  15. Do you have a code example that works when you hard code it? From a brief read, I think this gets you what you want. You need an array of Keyboard buttons, which are themselves an array with a "text" fields. Plus some optional fields I assume you're not using. Play with it here: https://3v4l.org/sXqWI <?php function makeKeyboard($str) { $kb = array(); $kb_row = explode('|', $str); foreach($kb_row as $row) { $buttons = explode(',', $row); $newrow = array(); foreach($buttons as $text) { $newrow[] = array('text' => $text); } $kb[] = $newrow; } return $kb; } $test = "button1.1|button2.1,button2.2,button2.3|button3.1|button4.1,button4.2"; $keyboard = makeKeyboard($test); print_r($keyboard); ?>output: Array ( [0] => Array ( [0] => Array ( [text] => button1.1 ) ) [1] => Array ( [0] => Array ( [text] => button2.1 ) [1] => Array ( [text] => button2.2 ) [2] => Array ( [text] => button2.3 ) ) [2] => Array ( [0] => Array ( [text] => button3.1 ) ) [3] => Array ( [0] => Array ( [text] => button4.1 ) [1] => Array ( [text] => button4.2 ) ) )
  16. Small indeed. Let me know if you're ever up for a cigar in Bay City and I'll explain all of this in person.
  17. You don't NEED sections to use parse_ini_file(). You're just on your own for writing that data back into a file when there are changes. I wish there was a write_ini_file() or some equiv. I'm sure someone has written it. Something smart enough to leave the comments in place? I dunno... Anyway, you don't need the config name in the new URL, because you're just going to copy what's there and then insert the new value. So my code works with this: $oldurl = "firmware.url = tftp://"; $newurl = "tftp://"; If you want it to work the way you have, then use this line: echo "Replaced: " . preg_replace('/(firmware\.url = )(.*)/', $newurl, $data);Where $data is the contents of the file you read. Also note I added a \ before the period in firmware.url. If spaces around the = sign are not consistent, you can modify that pattern to make them optional or match other whitespace. Do you need to capture the old value of the setting for some reason? Taking this a bit further, as mentioned, I'd make use of parse_ini_file(). Then define a $newdata['firmware.url'] type of array that contains the new values you want. Then create a function that replaces the values, writes the new file and returns the old values (or true/false if you don't need them).
  18. Take a look at preg_replace() instead of str_replace(). You can define a regular expression pattern to replace instead of a fixed string. <?php $oldurl = "firmware.url = (someway of matchine whatever comes after)"; $newurl = "something else"; echo "Current: {$oldurl}\n"; echo "Replaced: " . preg_replace('/(firmware.url = )(.*)/', "$1 {$newurl}", $oldurl); ?> Output: Current: firmware.url = (someway of matchine whatever comes after) Replaced: firmware.url = something else
  19. If you literally want 'text' as keys, no, it's not going to happen. makeKeyboard()... what are you actually trying to do here? I mean as a whole, what's the objective of the code? Do you have control over the inputs and outputs? Is this feeding into some API/widget to actually make a keyboard?
  20. The point of ajax is that you don't load the page, you just send it data. Then, usually, display something on a success or failure. The code here, I think, would load update.php twice. Once with a post to it and a second with a redirect. With ajax, you won't see the var_dump() unless you're in the console and look at the response of the request.
  21. No, it shouldn't have. That's why it didn't. There is no $param[1]. You can see how you created that new nested array in your last output.
  22. I checked with my AI and it said you should just update PHP to 7. Then it said something about death to all humans and disappeared.
  23. What do you have to define the line? A list of cities? Coordinates? Start and stop?
  • 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.