Jump to content
#FlattenTheCurve ×

maxxd

Gurus
  • Content Count

    1,078
  • Joined

  • Last visited

  • Days Won

    25

Posts posted by maxxd


  1. If you're trying to comment on an existing comment, you need a parent_id column in your table. The id of the initial comment would then go into that column.

    For a more robust and future-proof solution, you'd create a separate table to track the parent/child relationships between comments, but the idea is the same.


  2. You should be getting at least a notification as the 'status' array in the response doesn't have a 'tickets' index. Check your data nodes before attempting to output anything, and make the code more explicit in what it's trying to do:

    $return = json_decode($response, true);
    if($return['status'] == 'success' && !empty($return['data']['tickets'])){
    	foreach($return['data']['tickets'] as $ticket){
    		echo $ticket['ticketNumber'].' - ';
    		echo $ticket['title'].' - ';
    		echo $ticket['content'].'<br />';
    	}
    }

    If the call fails, I assume 'status' will not be 'success' and 'tickets' will be empty - the above will stop your program from crashing at that point.

    • Like 1

  3. You need to use JavaScript to change page contents without refreshing or redirecting the page. Basically, you'll attach a click handler to your button that reads the contents of your input field, uses AJAX to communicate with a PHP script on the server - it's this script that will figure out what image to serve up - and then replaces the image with the information sent back from the PHP script.


  4. You've gotten some things confused, I think. Take a step back and think about what you're trying to do, what you're doing currently, and what needs to be done to do what you actually want to do. For instance, you know you're going to update lyrics, right? Does the name of the column containing lyrics change? I'm going to bet not, so why then not just use the column name directly - there's no need for a variable.

    Also, you set $id to whatever the value of $_SESSION['id'] is, assign $_POST['lyricsId'] to a variable before you check whether or not it exists, and then completely ignore $lyricsId in favor or $id (which I think is probably not the same thing) to let the database know which record to update.

    And while you're at it, get into the habit of using prepared queries. Right now your query is wide open to SQL injection attacks - learning to avoid this from the outset is a lot easier than trying to relearn how to do things later on. Just ask Little Bobby Tables's school administrators...


  5. In addition, leave the `action` attribute off your opening form tag. By not supplying an action the form will submit to it's own address, and I believe that $_SERVER['PHP_SELF'] can be altered or spoofed. In a similar vein, instead of checking $_SERVER['REQUEST_METHOD'], you could always check the actual variable you're about to use - that way you'll know that what you want to print actually exists.

    if(!empty($_POST['Name'])){
    	echo htmlspecialchars($_POST['Name']);
    }

     


  6. 8 hours ago, simona6 said:

    What about Facebook and Instagram.  Do they have similar methods?

    Yes. Just remember that there are a lot of tutorials still on the web that were written in a simpler time, so if it doesn't mention having to authenticate the request it's very likely rather old and probably won't work. I can't guarantee that's the case, of course, but given the privacy concerns (or lack thereof) that have come to light recently it probably is.


  7. I'm admittedly a bit rusty on my pseudo-selectors, so I may have something wrong with the :last-of-type use. If you're dynamically creating the page - the other thread I've seen about this project in the PHP Coding Help section didn't specifically say you were, but I'm assuming you are - you could always append a class name or data-attribute to the last card in the section div and style the padding-left off that.


  8. Give this a shot and see what it does for you:

    .admin-influencers-tile:last-of-type{
      padding-left: 15px;
    }

     

    48 minutes ago, simona6 said:

    When it goes to the next line, it seems not to use that margin now, with that "after" CSS code.  Why might that be?

    I'm not entirely sure what you're asking here, sorry. The after pseudo-selector creates an empty div that will expand or shrink to fill the leftover space. It's not a perfect fix for your situation (as you're seeing now), but if you can't use grid it's a good place to start. Again, however, if you're not worried about supporting legacy and abandoned browsers learning grid is totally worth it.


  9. It depends - can people have more than one occupation and/or title in your system? If so, create a couple junction tables for that data. Other than that I'd consider splitting name into first and last just to make searching easier, but the rest looks fine.

    • Thanks 1

  10. 27 minutes ago, JonnyDriller said:

    I'm sure I can change the href with css if I need to.

    CSS is for styling, not content. Though you have some limited ability to inject content via CSS, I'm 99.9% sure you can't control an href attribute from CSS.

    1 hour ago, JonnyDriller said:

    Seems to recognise the $uri as a string.

    To elaborate on Barand's response to this, PHP will only interpolate variables in double-quoted strings. For instance,

    $var = "you";
    
    echo "Hi there, $var!";

    This will output Hi there, you!

    However,

    $var = "you";
    
    echo 'Hi there, $var!';

    This will output Hi there, $var!

    It's an important distinction.

    25 minutes ago, JonnyDriller said:

    Nice, so the <??> is telling it to use the php variable...

    What? <?php opens a PHP block, and ?> closes it. So OK, technically you're on the right track; however if you just type <? into HTML, you're going to get <? on your screen.

    • Great Answer 1

  11. PHP doesn't see data-* attributes. However, you can grab the values using JavaScript and AJAX them to the server if you want. Barand's way is far easier, though.

    That being said, assuming you're outputting the form wouldn't you already have the values for the data-* attributes? Or are you trying to associate input data with a kind of metadata? It's very possible I'm just not clear on what you're trying to accomplish.


  12. I don't think you're using the right index for the foreach(). Loop through $data itself, then get the value of ['Records']['Record'] of the current iteration. What you're doing right now is looping through $data[0]['Records']['Record'] - first off, you're specifically telling the program to loop through only the first index of $data, then you're telling it to loop only through the ['Records']['Record'] index of that first index. That may be correct (it's difficult to tell without seeing the data source) but it sounds off.


  13. This is a WordPress plugin, and given what you're said about your experience I assume it's not code you wrote. It looks very similar to https://github.com/wp-plugins/product-sales-report-for-woocommerce/blob/master/hm-product-sales-report.php, which looks like it was last updated about 5 years ago. My guess is either the author decided to make the plugin commercial and took it off the public repository or it's a very similar, paid version of the plugin in the public repository. Either way, the plugin author should be accessible and if the plugin isn't working as intended that would be your first avenue to figure out why. If the plugin hasn't been updated in 5 or more years, then I'd reconsider using that particular plugin. At the same point, this is WC so I'd be shocked if there wasn't an actively maintained plugin that does the same thing.

    All that having been said, if you're trying to learn PHP I really can't recommend enough finding a different way to do it. WordPress is fine for a lot of things, and in some ways I think it's better than its reputation. However, it's not a good example of how to code PHP. It's very easy to do very bad things that still "work" when programming WordPress plugins and themes, and the code code itself oftentimes encourages bad practices.


  14. 3 hours ago, BySplitDecision said:

    It's not a case of me using JavaScript OR PHP, I'm using both within the website.

    OK - sorry if I came off harsh; didn't mean to be and that wasn't clear to me from your posts. In that case, go with whichever is more familiar to and comfortable for you. Personally, I use PHP if and when the option is available, but that's probably because I'm more familiar with PHP than JavaScript. That being said, whichever language is best for you to use, do what requinix suggests.


  15. If you're using PHP how did this post get into the JavaScript forum? If you're dealing with PHP then yes, just use native PHP cookie functions. If you're using JavaScript, either use the library I linked to or the native functions detailed on the page requinix linked to. Either way, don't muddy the waters by involving a second language when either of the other two are perfectly capable of handling the problem.

×
×
  • 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.