Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. BTW - I gave you the general method for solving your issue but don't forget that you should do some alterations to make the query into one that can be prepared. That would involve (IMHO) using PDO and named args (:val1) to build the where clause and then an array of those args with their associated values before running the query. Here is what that should resemble: $sch_str = 'manchester university, eton college'; //trim($_POST['search']); $args = explode(',', $sch_str); $parms = array(); // start building the where clause value $where = ":val'"; $parms['val0'] = trim($args[0]); // finish buildilng the clause for ($i = 1; $i< count($args);$i++) { $where .= " or race_winner = :val$i"; $parms["val$i"] = trim($args[$i]); } $q = "SELECT Season, race_date, race_winner FROM trk_races WHERE race_winner = $where"; echo "query is <br>$q<br>Parms are:<pre>",print_r($parms,true),"</pre>"; This would then be followed by a call to prepare and then a query/execute using PDO
  2. Here is a sample from what I learned by doing a google search. It uses a string that resembles what you are trying to use but a different table structure which I hope is not too difficult for you to modify. $sch_str = 'manchester university, eton college'; //trim($_POST['search']); $args = explode(',', $sch_str); // start building the where clause value $where = "'" . trim($args[0]) . "'"; // finish buildilng the clause for ($i = 1; $i< count($args);$i++) $where .= " or race_winner = '" . trim($words[$i]) . "' "; $q = "SELECT Season, race_date, race_winner FROM trk_races WHERE race_winner = $where"; echo "query is <br>$q<br>"; Note that I have required that your user enters each desired argument to be comma separated.
  3. Then perhaps you shouldn't be doing this. Unless of course it is homework and you have to do it. In that case, Do It. Talk to your teacher. Go to class more. Read the textbook. Don't simply ask us to do your homework.
  4. A google search tells me that you must explode your incoming field with the words on the spaces between them. Then implode that array with an ' or ' and the field name to be searched. Then use that string as your where clause value. Have at it!
  5. What does one have to do with the other?
  6. Now study the difference in the original 'bad' line and the new line I gave you. Compare that to the syntax that the error message showed you and note how the parens have to be placed. Did you just move a parens on that line, causing this issue?
  7. As I said first thing -- the style of this code is not allowed at all. It has to be re-written. These new lines are not the same as the one you have the error on. They do not follow the same format as the bad one. I have no idea what the app is supposed to do for you but it is written rather tediously and I would have definitely found another way to do this that the mind-numbing way that the original code chose. I'm guessing that he/she too was a noob when writing it. Try this: $coronavirus_notice_banner_color = @$_POST['action']=='save_coronavirus_notice_plugin' ? $coronavirus_notice_banner_color : (get_option('coronavirus_notice_banner_color') ? esc_html(get_option('coronavirus_notice_banner_color')) : '#CC0000'); And I really don't like the use of the @ in this code. It is not a good practice.
  8. I believe it is telling you that the complex statement that someone wrote there is no longer supported (if it ever was). Putting 2 of these comparisons together is silly coding in my book just to supposedly save some coding space or whatever. But it is difficult to re-interpret when you come back to it 3 months later. It also seems to be very incorrect. (Are you sure you copied it correctly?) To explain. The first that has the POST in it is a test against a string value. It is true then you are returning the value of the 'banner color' to the result var, which IS that same value. If it is not true then you are doing another (similar) test of the result of a call to getoption which if it returns a true value will return the value of a call to the esc_html function but if it is not true will simply return a color value (#cc0000). To put it in a different way: if ($_POST['action'] == 'save_corona_virus_notice_plugin') $coronavirus_notice_banner_color = $coronavirus_notice_banner_color; elseif(get_option('coronavirus_notice_banner_color')) $coronavirus_notice_banner_color = esc_html(get_option('coronavirus_notice_banner_color')); else $coronavirus_notice_banner_color = '#CC0000'; I don't see a parens problem here. But I see some highly unnecessarily complex variable names. Way too much typing.
  9. The above line makes an array having one element (0) whose value is 'nospam'. What are you planning to do with that array? I don't see it referenced but it still seems like a funny thing to be doing. You are doing a check for the entry in this field but not with the array you have created. Perhaps you simply want to create it near the top of your script as a simple static variable and not an array? and then maybe you want to change this if ($post['secretcode'] != 'nospam') To be if ($post['secretcode'] != $secretcode) BTW - You seem to be doing this thing with your own version of the $_POST array for no good reason. Is this something you read about somewhere that is supposed to be of help to your algorithm? Why not just use $_POST? It's a global array that you control and is accessible from your entire script.
  10. Not sure what you are attempting with the above but since the setting is only good for the duration of the script's execution, you really s/b thinking of doing an E_ALL as well as a display on the client's screen to aid in debugging your script easier. error_reporting(E_ALL); ini_set('display_errors', '1');
  11. You have an array reference without quotes on it. It thinks that's a constant when it is supposed to be an index value. The error message should have pointed this out to you.
  12. If you don't know a thing about php it's kinda hard for us to communicate with you. You need to get some understanding of it first.
  13. find a php tutorial online and start reading and practicing
  14. We are more than willing to give you some help but can't do it without seeing that code. ??
  15. If what Mac_gyver says is true then I totally agree. Read the manual and look at the examples for using PDO instead of mysqli. Better choice and pretty easy.
  16. HOw is this related to phpadmin? And if you want help, show us the code that the message is pointing to.(and maybe a few lines before that)
  17. Make the user provide some token ( a word presented to human eyes or a text answer) that your script has to see in the post array.
  18. Showing us 1 line of code and asking for help is kind of impossible.
  19. For something that seems so easy it almost surely is homework. Needs to attend his programming classes as well as his spelling and writing classes
  20. Oops. youll have to play with the % sign. I put it in the wrong place. " votes (" . $pct . "%)<br><br>";
  21. How about this? $stmt = $modx->prepare("SELECT * FROM `modx_ltda_vote` ORDER BY `option` ASC"); if ($stmt->execute()) { $sum = 0; $output = array(); while($row == $stmt->fetch(PDO::FETCH__ASSOC)) { $sum += $row['total']; $output[] = $row; } foreach ($output as $line) { $pct = number_format(($line['total'] / $sum)*100, 2); echo $line['option'] . ' has ' . $line['total'] . " votes (%$pct)<br><br>"; } } else echo "Query did not execute"; Did not test.
  22. Again - we POST the code. People dont like to click links to places they don't know. Please use the <> icon to post it neatly. Of course Mac_gyver may have already solved your problem for you.
  23. Usually code is posted as CODE, not a picture. Makes it easier to read and to perform edits on it should we have something to help you.
  24. How are your front end and database 'connected'? FWIW - the forum is here to help those who are having coding issues. We don't write apps for noobs who haven't learned anything at all.
  25. And I think that is what I showed you. The 'anchor' is the <a> tag that you build to do just what you asked.
×
×
  • 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.