Jump to content

Barand

Moderators
  • Posts

    24,342
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. Is the date the same "Year End" for all players or is it different for each player depending on their renewal date?
  2. You have corrected the syntax error. Does it work? I have no way of knowing what your variables contain or what your custom methods are returning, therefore cannot comment further.
  3. It won't throw an error, just a notice, so it will depend on the error reporting level. Notice: Use of undefined constant cart_qty It will assume it is the string value 'cart_qty'.
  4. That's only one of the problems. What is "$query = ... " there for? You don't use it. "test2" and "test4" are string values so should be quoted in the WHERE clause. (test1 = 'test2' AND test3 = 'test4'). Yours is only correct for numeric values. Your method should return the result, not echo it. [edit] You will probably hit further problems if you have a mix of bind values (AND/OR)
  5. You can see if "secure_file_priv" is set, and what its directory value is (if it is set) with SELECT @@secure_file_priv; Is your mysql server on the same pc as that E drive? (The recommended place for image storage is the server's file system and store its location and other metadata in the database)
  6. That answers the "how" question, but have we answered your original question, viz. "Why isn't it able to find the max value if it's less than 5?"
  7. Instead of ... ob_start(); $stmt->debugDumpParams(); $sql = ob_get_contents(); ob_end_clean(); //$sql = strtok(substr($sql, strpos($sql, '] ')+2), "\n"); $start=strpos($sql, '] ')+2; $sql = substr($sql, $start, strpos($sql, "\nParams:") - $start); why don't you use ... $sql = $stmt->queryString;
  8. That way is far too easy.? (In defence of my method, it would enable the extraction of all contest/category winners with a single query)
  9. I can't see your data but one possible explanation is that you have a situation like this mysql> select * from contest_entries; +----------+------------+-------------+---------+-------+----------+ | entry_id | contest_id | category_id | user_id | votes | e_status | +----------+------------+-------------+---------+-------+----------+ | 1 | 5 | 8 | 101 | 2 | 0 | | 2 | 5 | 8 | 102 | 3 | 0 | | 3 | 5 | 8 | 103 | 4 | 0 | | 4 | 1 | 9 | 104 | 1 | 0 | | 5 | 1 | 9 | 105 | 3 | 0 | | 6 | 1 | 9 | 106 | 5 | 0 | +----------+------------+-------------+---------+-------+----------+ The MAX(votes) is 5, but that was in contest 1, category 9. Your query for contest 5 therefore returns no match. mysql> SELECT entry_id -> , user_id -> , votes -> FROM contest_entries -> WHERE contest_id = 5 -> AND category_id = 8 -> AND e_status = 0 -> AND votes = (SELECT MAX(votes) FROM contest_entries) -> LIMIT 1; Empty set (0.00 sec) Possible solution... SELECT entry_id , user_id , votes FROM contest_entries c JOIN ( SELECT contest_id , category_id , MAX(votes) as votes FROM contest_entries GROUP BY contest_id, category_id ) mx USING (contest_id, category_id, votes) WHERE contest_id = 5 AND category_id = 8 AND e_status = 0 LIMIT 1; +----------+---------+-------+ | entry_id | user_id | votes | +----------+---------+-------+ | 3 | 103 | 4 | +----------+---------+-------+
  10. Just my 0.02 worth ... 1. It is always a bad idea to place values provided by the user ($_GET, $_POST, $_COOKIE) directly into your SQL. A better way is this, which avoids doing that and also checks that only valid column names can be used $sort = $_GET['sort'] ?? ''; switch ($sort) { case 'recd_date': $orderby = 'location, recd_date, name'; break; case 'sent_date': $orderby = 'location, sent_date, name'; break; case 'birth_date': $orderby = 'location, birth_date, name'; break; default: $orderby = 'location, name'; break; } 2. Use prepared statements to place values into your query $result = $db->prepare("SELECT * FROM $company WHERE member = ? ORDER BY $orderby "); $result->bind_param('i', $member_number[$i]); $result->execute(); 3. The use of that [$i] index - are you running the query in a loop for different member_numbers? Don't. 4. You have a variable table name ($company) which suggests you have several tables, each for a different company. Better to have a single table and add an indexed "company" column.
  11. Have you checked what "$sort" contains when it isn't working?
  12. The comma, though not required, was OK. It was an array separator and not a statement terminator.
  13. Perhaps you you could ask the API providers to present a more user-friendly interface using JSON EG {"action":"Added","quantity":"1","item_code":"RNA1","product_name":"Mens organic T-Shirt","colour":"white","size":"XL"}
  14. It's the first element in the array. $str = $arr[0];
  15. explode() the string on the ";" to get 6 sections, then explode() each section on the ":" to get get keys and values
  16. What is the code that is giving you the $arr variable in that format in the first place?
  17. Are you calling "session_start()" at the beginning of the second page? +1
  18. Is this close to what you want? $a = json_decode($json, 1); $new = []; foreach ($a['table6'] as $k => $v) { if (array_filter($v)) $new[$k] = $a['table6'][$k]; }
  19. As the comment in the code says - if URL is blank it calls itself.
  20. How should I know? That's your first mention of a startPublishing() function. The code I posted is a functioning, stand-alone script. Do with it what you want.
  21. Try this <?php require 'db_inc.php'; $db = pdoConnect('test'); /*** INITIALISE TABLE - only required once *********************************************************** $db->exec("CREATE TABLE IF NOT EXISTS broadcast( id int not null primary key, streamid varchar(20)) "); $db->exec("INSERT IGNORE INTO broadcast VALUES (1, '0')"); */ // // HAS AN AJAX POST BEEN SENT? // if (isset($_POST['streamid'])) { try { $stmt = $db->prepare("INSERT INTO broadcast (id, streamid) VALUES (1, ?) ON DUPLICATE KEY UPDATE streamid = VALUES(streamid) "); $stmt->execute( [ $_POST['streamid'] ] ); exit($_POST['streamid']); } catch (Exception $e) { exit("ERROR"); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> function randomToken() { return Math.random().toString(36).substr(2) } $().ready( function() { $("#btnSend").click(function() { var tok = randomToken() $.post ( "", // blank - calls self {"streamid" : tok }, function (resp) { alert(resp) }, "TEXT" ) }) }) </script> </head> <body> <button id="btnSend">Send Stream ID</button> </body> </html>
  22. Not true. Connections are made to a server, not a database. This works just fine. define("HOST",'localhost'); define("USERNAME",'?'); define("PASSWORD",'?'); $db = new PDO("mysql:host=".HOST,USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $res = $db->query("SELECT 7 * 6 "); echo $res ->fetchColumn(); //--> 42 Of course it would fail if I tried to access columns from a table (in an unspecified DB)
  23. "color" attribute refers to content "border-color" refers to border. try 'border: 1px solid red'
  24. I think the problem is this line ... $update->bindParam(':item_qty', $item_q - $_POST['item_qty'][$k]); ... where you are attempting to bind an expression and not a variable. Try changing the query (and you also need to bind the category) $update = $pdo->prepare(" UPDATE stocks SET item_qty = item_qty - :item_qty -- changed line WHERE category = :category AND product_name = :product_name AND item_size = :item_size AND item_type = :item_type "); foreach($_POST['category'] as $k => $category){ $update->execute( [ ':item_qty' => $_POST['item_qty'][$k], ':category' => $category, ':product_name'=> $_POST['product_name'][$k], ':item_type' => $_POST['item_type'][$k], ':item_size' => $_POST['item_size'][$k] ] ); }
×
×
  • 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.