Jump to content


Popular Content

Showing content with the highest reputation since 12/22/2019 in all areas

  1. 3 points
    Don't use $GLOBALS. Forget it exists. There is never a good reason to use it. Pretend you never saw it.
  2. 2 points
    For example, https://www.php.net/manual/en/datetime.createfromformat.php https://www.php.net/manual/en/datetime.format.php
  3. 1 point
    If this is true, then why is there a problem? Make a users account, process their payment, and move on. If the payment fails just don't grant them any entitlement. Just because you put everything on one page for the user to enter their information doesn't mean you have to process it as an all-or-nothing thing. You can still process it as separate actions and handle any problems appropriately. For example, if the payment fails keep the account information and just send them to a payment form (similar to what you'd do for a member who's subscription is expired). You need a way for someone to be registered without an active subscription. Whether or not that user can do anything is up to you. Allowing a little bit of bonus abilities for simply registering is a common and good way to get people to hop on board. Registered users are easier to track and manage than a bunch of anonymous people. If you ever want to do something like sell ads or potentially the website as a whole having statistics about usage will be very beneficial and registered users can give you some good statistics.
  4. 1 point
  5. 1 point
    Why in the world would you store it that way in the first place? Thought it may work now, down the road who knows what kind of problems this will present. Now is the time to fix the schema so it makes sense.
  6. 1 point
    I know it sounds like a fun project to emulate something that already exists. But - just exactly why do you think it necessary? There is already a $_SESSION array (RTFM) and the ability to make specific local vars global for your entire script (see 'global') . So what design of yours is going to need your own new version of this? Besides - good programming practice does not include making everything globally available.
  7. 1 point
    You can't just copy code and necessarily expect it to work. You need to understand the code presented and then implement your own.
  8. 1 point
    most likely, either your actual database name contains some non-printing/white-space character(s) or the Config::get() method, which you haven't posted the code for, is adding some non-printing/white-space character(s) to the value (i'm betting either a new-line or a <br> tag.) this code is just adding an unnecessary, pointless layer. it has no useful error handling, is using emulated prepared queries (the default), cannot be used with a LIMIT x term in a query, and can't be used with more than one connection or a different database type. if you want to do something useful for a database class, extend the PDO class and add a general prepared/non-prepared query method that will use a prepared query if there are input parameters and will use a non-prepared query if there are not. when you make the database connection, you should set the character set to match your database tables, set the error mode to exceptions, set emulated prepared queries to false, and set the default fetch mode to assoc (assoc works best when dynamically processing fetched data.)
  9. 1 point
    IMHO it's easier just to do both inserts in the same loop as you always want one of each. ////////////////////////////////////// // menu item and connection insert // ////////////////////////////////////// $ins_i = $conn->prepare(' INSERT INTO ssm_menu_items (menu_item_name) VALUES (?); '); $ins_c = $conn->prepare(' INSERT INTO ssm_menu_connection (menu_id, menu_item_id) VALUES (?,?) '); $ins_i->bind_param('s',$nmItem); $ins_c->bind_param('ii', $menuInsId, $menuItmInsId); foreach ($_POST['newMenuItem'] as $nmItem) { $ins_i->execute(); $menuItmInsId = $stmt->insert_id; $ins_c->execute(); }
  10. 1 point
    FYI, this can be (and should be) handled entirely with CSS using nth-child(), not(), and first-child.
  11. 1 point
    i'm going with the code never copies the (unnecessary) $cart_items variable back to the session variable, so the code starts over each time it gets executed. just use $_SESSION["cart_items"] everywhere and forget about the $cart_items variable.
  12. 1 point
    Your misleading choice of variables names no doubt contributed to the problem. There are other things could be improved too Use prepared queries instead of putting variables directly into the sql query strings. (I would also recommend PDO in preference to mysqli) use css classes instead of repetitive inline style definitions you are using deprecated html markup code (eg <tr bgcolor = "#cccccc">) you use a lot of unnecessary concatenation when building strings - a common source of errors.
  13. 1 point
    In your pagination loop you set all the links to the same page number! Should be $data = array( 'page' => $current_page, <-- CHANGED 'country' => $cleaned_current_page_country );
  14. 1 point
    session_start will automatically determine if your starting a new session or resuming one that already exists, but this is not what your error is referring to. The error you're seeing relates to calling session_start multiple times within the same request. The function is only intended to be called once at the start of your request, which is not the same as at the start of every *.php file you have. If you want to have your separate pages that people request and not re-design your application to use a common front-end script or some framework then what you should do is have a common include file that handles your session (and other stuff as needed) and include that in each of your main entry pages using require_once. So your entry points should be coded something like: <?php require_once './includes/common.php'; //whatever else your script does And your common include would just be <?php session_start(); //whatever other common code you want This common include could contain things like your session management code, database connection code, function definitions, etc. Note: there's also a php.ini setting called session.auto_start. If you've enabled that then you don't need to manually call session_start().
  15. 1 point
    I have just noticed you don't use the $page_url in those pagination links. It looks like you intended to but then just used the query string $the_query = http_build_query($data); $page_url .= '?' . $the_query; echo '<li><a href=" '.$the_query.' ">'.$current_page.'</a></li> '; As you go to the same page that should be sufficient but I think you will need the preceding "?" Try $the_query = http_build_query($data); $the_query = '?' . $the_query; echo "<li><a href=\"$the_query\">$current_page</a></li>";
  16. 1 point
    the most immediate problem is you are not using the correct $_POST field and table column in the WHERE clause in the SELECT query (edit: i realized while writing this that the SELECT query you have shown is part of the update process, to retrieve a specific row of data to populate the form fields with, not part of a name search.) if you are entering the name (or partial name) of a game to search for, wouldn't you be searching the table column holding the game's name? why are you trying to match the id column? next, don't write code like this. there's a bunch of problems that have resulted in a wall of code that's both insecure and has created a 'cannot see the forest for the trees' problem (which is perhaps why you are using the wrong field/column in the WHERE clause.) a laundry list of issues - don't create a bunch of discrete variables for each different form you write code for. this is just a waste of typing time. instead, operated on the form data as a set, by keeping the data as an array, and operating on the elements in the array. by using exceptions for database statement errors, any connection, query, prepare, and execute error will transfer control to the exception handler. therefore, any discrete error handling logic in your code won't ever be executed and should be removed. related to #2, the only exception handling try/catch block you should have in your code are for those errors that are recoverable, that your code can do something about, such as dealing with the inserting/updating of duplicate or out of range user submitted data. all other database statement errors are non-recoverable and there's no good reason for your code to catch these exceptions. just let php catch and handle these exceptions. by using exceptions for errors and letting php catch them, php will use its error related settings to control what happens with the actual error information (database statement errors will 'automatically' get displayed or logged the same as php errors.) 'function getPosts()' - don't do this. you want code to be easy to write and debug and be readable by everyone. by intentionally using numerical indexes, you have made more work while writing this code and made more work for anyone trying to read/maintain the code. also, once you write and test the code for a function, you should not find yourself regularly editing the code. functions should not contain application specific code that you must change each time you do something new. external data can be anything and cannot be trusted. you must validate all external data before using it. you should use a prepared query when supplying external/unknown data to the sql query statement. items #6 and #7 will help avoid the current error, because you would not attempt to run a query if an expected input is empty and a numerical input that can be empty/null won't produce a query error. a name or partial name search can match more than one row (the same game name for more than one platform.) you would loop over the result from such a query and display as many rows of data that the query matched. to update/delete the data for a specific row, you would produce an edit link and a delete form for each row that is displayed. the edit link would contain the id of the row. when you click the edit link, the code would query for an fetch the data matching that row and populate the form field values. the current SELECT query seems to be for this part of the process, not for a name search. you need one more SELECT query.
  17. 1 point
    One more attempt. Here's a script which puts the hints I gave you into practice. As you can see, it splits the ordered items into separate order depending on the SKU group SAMPLE: Code (read, understand what's going on and learn. Refer to php.net manual if you don't know what something does.) (Not an elseif()..elseif() to be found!) <?php const HOST = 'localhost'; # const USERNAME = '????'; # const PASSWORD = '????'; # const DATABASE = '????'; # These lines would # function pdoConnect($dbname=DATABASE) # normally be in { # $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); # an included file $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); # return $db; # } # $pdo = pdoConnect(); // // CREATE TEST DATA USED BY THIS EXAMPLE // $pdo->exec("CREATE TABLE IF NOT EXISTS aveeva ( id int not null auto_increment primary key, order_no int, sku int, product varchar(50), qty int ) "); $pdo->exec("REPLACE INTO aveeva (id, order_no, sku, product, qty) VALUES (1,1020345, 12345, 'Pair of left-footed socks', 2), (2,1020345, 35547, 'Square Hula hoop', 1), (3,1020345, 12346, 'Pair of right-footed socks', 2), (4,1020345, 62347, 'Pair of three-legged tights', 5), (5,1020345, 45501, 'String vest', 1), (6,1020345, 45501, 'Thermal long johns (red)', 2), (7,1020345, 22105, 'Staffordshire pot dog', 2), (8,1020345, 38962, '250 Kg dumbell set', 1), (9,1020345, 23176, 'Ming vase', 1), (10,1020345, 23194, 'Porcelain elephant', 1), (11,1020345, 38547, '0.5 metre yoga mat', 1) "); // DUMMY CLASS TO PROVIDE THE METHODS YOU USED class Magee { private $fromName; private $body; private $subject; private $type; private $sendTo; public function __construct() { } public function setFromName($str) { $this->fromName = $str; } public function setBody($str) { $this->body = $str; } public function setSubject($str) { $this->subject = $str; } public function setType($str) { $this->type = $str; } public function setToEmail($str) { $this->sendTo = $str; } public function send() { // // Instead of sending emails // we just build content // for demonstration output // $out = "<fieldset><legend>TO: {$this->sendTo}</legend> <label>From</label>{$this->fromName}<br> <label>Subject</label>{$this->subject}<br> {$this->body}<br> "; $out .= "</fieldset>"; return $out; } } #Magee // define email addresses for the sku groups const DEFAULT_ADDY = 'other@gmail.com'; $addys = [ 2 => 'abc@gmail.com', 3 => 'xyz@gmail.com', 4 => 'qwe@gmail.com' ]; $res = $pdo->query("SELECT sku , product , qty , order_no FROM aveeva ORDER BY order_no, sku "); $orders = []; // // Split the items for each order // into groups depending the first // digit of their SKU // foreach ($res as $r) { $ono = array_pop($r); $sku1 = substr($r['sku'], 0, 1); if (!isset($addys[$sku1])) { $sku1 = 0; } $orders[$ono][$sku1][] = $r; } // // Build the email bodies from the array data // $emailsSent = ''; foreach ($orders as $ono => $odata) { foreach ($odata as $sku1 => $sdata) { $message = "<table border='1'> <caption>Order No: $ono</caption> <tr><th>SKU</th><th>Product</th><th>Quantity</th></tr>\n"; foreach ($sdata as $item) { $message .= "<tr><td>" . join("</td><td>", $item) . "</td></tr>\n"; } $message .= "</table>\n"; $emailsSent .= sendMailbasedOnSku($message, $addys, $sku1); } } function sendMailbasedOnSku($message, $addys, $sku1) { $emailTemplate = new Magee; $emailTemplate->setFromName('GIRI Test mail'); $emailTemplate->setBody($message); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); // GET THE APPROPRIATE EMAIL ADDRESS $sendTo = $addys[$sku1] ?? DEFAULT_ADDY; // USE IT $emailTemplate->setToEmail($sendTo); return $emailTemplate->send(); } ?> <html> <head> <title>Example</title> <style type='text/css'> body { font-family: clibri, sans-serif; font-size: 11pt;} fieldset { width: 70%; margin: 16px auto; padding: 16px;} legend { background-color: black; color: white; padding: 4px;} label { display: inline-block; width: 120px; font-weight: 600;} table { width: 50%; margin: 16px auto; border-collapse: collapse;} th { background-color: black; color: white; padding: 8px;} td { padding: 4px 8px;} </style> </head> <body> <?=$emailsSent?> </body> </html>
  18. 1 point
    Your problems are mainly because you are trying to write code before you have learnt to read. In my first post I said you needed 2 things. The first you have totally disregarded despite my spoonfeeding you the required code. The second addresses the problem you are now having and has also been ignored. Good luck and goodbye.
  19. 1 point
    Don't think about it in terms of references. Those are really just about &s. What PHP does with everything, not just arrays, is called copy-on-write. Meaning PHP will reuse a value up until you try to change it. That is when it starts making a copy. That's why they say never to use references to save memory: PHP is already saving memory for you.
  20. 1 point
    Get a copy of MySQL Workbench. There's a right-click menu option to go straight to it.
  21. 1 point
    First please use the code icon (<>) and choose PHP. It makes your code much easier to read. Which is line 118? Did you echo all your variables to make sure they contain what you expect?
  22. 1 point
    @mac_gyver gave the correct way to do it - http_build_query() EG $url = 'http://localhost/board/italian.php'; $data = [ 'page' => 2, 'country' => 'italian', 'comment' => 'this is a (simple) comment' ]; $qstr = http_build_query($data); $url .= '?' . $qstr; echo $url; //--> http://localhost/board/italian.php?page=2&country=italian&comment=this+is+a+%28simple%29+comment Note the encoding of the query string
  23. 1 point
    When you install a fresh wordpress website, the CMS by default create TWO config-php files which are: wp-config-sample.php wp-config.php Once, installation is done, then it is always recommended to remove "wp-config-sample.php" from the server, so that hackers can't use it to hack your website. Now coming, to your question, where did you added the DB Name, ID and Password? But, if your website was already live and shifted your wordpress website from one server to another then you may notice an 404 error all across the pages. This may be because of SSL issue and .htaccess. You may have to install and activate ssl on your website using cpanel read this. My website issue fixed using ssl installation.
  24. 1 point
    Oh damn, I didn't even see this thread when it was first created. Yeah, I don't know what happened. Nobody changed anything. Couple days ago I applied the latest IPB patch and the problem went away. I suspect it was some sort of template caching problem.
  25. 1 point
    There's no context around the code you've posted, but there appear to be a couple issues. First and foremost, you're using get_currentuserinfo() , which is deprecated in favor of wp_get_current_user(). Even beyond that, you're requesting the data of the currently logged in user, which is you. So actually your code is doing exactly what you've asked it to do. Another issue is that you're calling get_currentuserinfo() multiple times - if all this code is in the same template you don't need to do that. Give some context to what you're trying to do with this code. If you're in the WordPress loop, use the information about the current post.
  26. 1 point
    Of course, you could store the city and the full school name, then using the technique we discussed in this forum a couple of weeks ago, remove the city from the school name when required. I.E. SELECT school , city , TRIM(REPLACE(school, COALESCE(city,''), '')) as short_school FROM school; +------------------------------+----------------+----------------------+ | school | city | short_school | +------------------------------+----------------+----------------------+ | Bloomington North | Bloomington | North | | Columbus East | Columbus | East | | Fort Wayne Bishop Dwenger | Fort Wayne | Bishop Dwenger | | Neil Armstrong High | NULL | Neil Armstrong High | | Davy Crockett School | San Antonio | Davy Crockett School | | Kokomo | NULL | Kokomo | | Logansport | NULL | Logansport | | Marion | NULL | Marion | | Jefferson | Lafayette | Jefferson | | McCutcheon | Lafayette | McCutcheon | | Harrison | West Lafayette | Harrison | | Carmel Greyhounds | NULL | Carmel Greyhounds | | Zionsville Eagles | NULL | Zionsville Eagles | | Fishers Tigers | NULL | Fishers Tigers | | Noblesville Millers | NULL | Noblesville Millers | | Westfield Shamrocks | NULL | Westfield Shamrocks | | Hamilton Southeastern Royals | Hamilton | Southeastern Royals | +------------------------------+----------------+----------------------+
  27. 1 point
    IMO, you are just creating a problem mixing data. It doesn't matter if the school name is the same as the city. A city is a city, a school is a school.
  28. 1 point
    They are part of the language. Whenever possible you should always use the built in types and functions unless you have a very good reason not to.
  29. 1 point
  30. 1 point
  31. 1 point
  32. 1 point
    You simply rename wp-config-sample.php to wp-config.php or check this guide to fix database connection error. https://www.webminto.com/how-to-fix-error-establishing-a-database-connection-in-wordpress/
  33. 1 point
    Must be a really old book. What you should do is actually learn how to program with PHP instead of throwing code into files and tweaking it until it works.
  34. 1 point
    He's testing for 0 or 1. 0! and 1! both equate to 1, so no need to calculate any further. Every recursive function needs a stop condition otherwise you quickly overflow the stack with an infinite recursion.
  35. 1 point
    I was assuming that a report_filed meant they attended. But, yes, you could mysql> SELECT weekofyear(start_time) as wkno -> , SUM(is_no_show=0 AND is_cancelled=0) as attended -> , SUM(is_no_show=1) as no_shows -> , SUM(is_cancelled=1) as cancellations -> FROM heartstring -> GROUP BY wkno; +------+----------+----------+---------------+ | wkno | attended | no_shows | cancellations | +------+----------+----------+---------------+ | 40 | 2 | 0 | 0 | | 41 | 0 | 1 | 1 | | 42 | 1 | 0 | 0 | | 43 | 0 | 1 | 0 | +------+----------+----------+---------------+
  36. 1 point
    It would help to see what your db data looks like EG, is it +------------+-----------+-----------+----------+ | start_time | no_shows | cancelled | attended | +------------+-----------+-----------+----------+ | 2019-12-20 | 1 | 0 | 0 | | 2019-12-21 | 0 | 0 | 1 | | 2019-12-22 | 0 | 1 | 0 | If so, then SELECT weekofyear(start_time) as weekno , SUM(no_shows = 1) as no_shows , SUM(cancelled = 1) as cancelled , SUM(attended = 1) as attended FROM mytable WHERE start_time BETWEEN ? AND ? GROUP BY weekno;
  37. 1 point
    Make sure all databases, tables, and columns, as well as the connection settings, use UTF-8. Make sure your PHP files are saved with UTF-8 encoding. Make sure your webpages use UTF-8 encoding.
  38. 1 point
    becomes... $sql_2_2 = "UPDATE analytics SET visitor_visitor_sessions = ?, visitor_visitor_pageviews = ?, visitor_visitor_pages = ? WHERE visitor_visitor_id = ? "; $stmt = $this->db->prepare($sql_2_2); $stmt->execute( [ $analytics['visitor_visitor_sessions'], $analytics['visitor_visitor_pageviews'], $analytics['visitor_visitor_pages'], $visitor_visitor_id ]);
  39. 1 point
    There is nothing in that code to sort the results in the array. readdir() (as stated in the manual) returns the results " . . . in the order in which they are stored by the filesystem". You could determine the file date and sort by that, but since you are copying them from one device to another, there is a good chance that the file date will be changed in that process. Sometimes the date changes in a copy process and sometimes it does not - depends on the process used. Also complicating things, filetime() will return different values based on the filesystem. As I understand it, in Windows it returns the creation time, whereas in Unix it returns the modification time. So, you could potentially sort using filetime() IF the original file creation times are preserved after they are copied AND filetime() returns the creation date. You should be able to verify if those are both true in your case. If so, get the creation date using filetime() and sort on that. If that is NOT the case, then you could either ensure they are copied in the correct order (i.e. one at a time in the order they were created) or you need to sort using some manner. For example, the named of the files is sequential. So you could sort by file name. But, when you go from IMG_9999.jpg to IMG_10000.jpg it will break that logic as IMG_1... comes before IMG_9... when sorting alpha-numerically. Of course, you could always parse the file names and convert them to have x number of digits, i.e. IMG_9999.jpg converts to IMG_0009999.jpg and IMG_10000.jpg converts to IMG_0010000.jpg. Also, your phone *may* restart that numbering at some point which basically screws all of that up. So, lots of possibilities, but no bullet-proof solution. The *best* solution would be predicated on the questions on how the files are handled in the environment (dates when copied, whether file names change, etc.).
  40. 0 points
    The error is complaining about a comma in the code. There is no comma in that code.
  41. 0 points
    Have you tried adding some tracing to that code to see what it is doing, shows you values of things, etc? And who uses js script tags in the middle of their php logic?
This leaderboard is set to New York/GMT-05:00
  • Newsletter

    Want to keep up to date with all our latest news and information?
    Sign Up
  • 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.