Jump to content

NigelRel3

Members
  • Posts

    69
  • Joined

  • Last visited

NigelRel3's Achievements

Regular Member

Regular Member (3/5)

4

Reputation

7

Community Answers

  1. As I started writing C - not a surprise that I use K&R. The reason I was talking about consistency with brace placing is that the PHP-FIG PSR-2 style (http://www.php-fig.org/psr/psr-2/) uses what I see as inconsistent brace placement... public function sampleMethod($a, $b = null) { if ($a === $b) { bar(); } elseif ($a > $b) { $foo->bar($arg1); } else { BazClass::bar($arg2, $arg3); } }
  2. Same here - find a style and just stick to it. IMHO there are issues with all of them, but the main thing is consistency makes it easier to read code. Personally I've always done function someName() { } Which is consistent with other things like if ( someDodgyComparison == true ) { while ( thereIsMoreToDo == true ) { } }
  3. I agree - it could be an indication that something is wrong - but data can be sourced from all sorts of places, sometimes it is a case of just having to deal with it. It's especially the case when the data is from a third party and there may be nothing you can do with the source data, you massage it to fit into what you need. Working with data loads can provide a great insight into what people try and do and your left with the impression that relying on people to do anything correctly and consistently is like trying to juggle water.
  4. Your check if the shirt number already exists is checking that a player_id already exists - nothing to do with the shirt number (or team)! I'm not sure if your database structure is correct though - if a player is just part of one team - then put the team number on the player record . If you want players to be in multiple teams - then put shirt number of the other record. Then create a unique key on team, shirt number.
  5. Have you tried... trim(TRAILING ']' from trim(leading '[' from g.field_value))
  6. If you want to fetch each value separately then SELECT `adequacaos`, count(`adequacaos`) FROM `rel_atividades_avaliacao` group by `adequacaos`; should give you some totals
  7. The message - Deprecated: mysql_connect() should give you a hint, if you read up on this you will see that you should follow the suggestion that it gives and change the way you interact with the database. So - yes - this is causing the database to not be updated.
  8. You would have to identify just the rows that have changed and update them, so it means finding the players that have been changed and using the match id and old player id to update that specific row to have the new player id.
  9. It would help if you can give the source script and the results, just saying something doesn't work is impossible to solve.
  10. You will have to rename one of the fields as having 2 fields called id isn't that helpful. As for how to compare two values passed into a script - it would be better for you to attempt something and post where you are struggling rather than just ask 'how can I achieve that'! This is something fairly trivial and should be quick to work out from almost any example using parameters.
  11. If I were to do as you are trying to do, I would pass the object in rather than have to add another stage of fetching the data from the object to then pass into the table layer. One thing which you should certainly change is that you should use bind variables for your PDO statements! Do not just dump data directly into any SQL statement.
  12. On the subject of how to catch/manage errors (exceptions or any combination) - is there a common way in which a PHP applications can trap, log errors and then present the user with a 'Something went wrong' screen, or is this down to individual implementations? I can see the problem here is that this relies on all of the potential areas for errors being complete prior to building any screen output - or does it? Is this something a framework would have built in (am starting to look into Lavravel). (Sorry for asking so many questions as I'm trying to find out as much as possible from people who actually do these things)
  13. Hmmm... I've changed it to print_r($db->errno); $msg = "SQL failed -".$db->error; And that now gives me 0 as the errorno (even though in the Variable panel I can see a value of 1146 at the point of executing that statement. Once I've stepped over the print_r line, the values are reset. Think I may have found the culprit - the very helpful debugging. If I run the code without debugging, it works as expected, through debugging must be doing as you've said and causing some side effects by getting statuses or something. I use Eclipse and XDebug which although is very useful at times, I must remember that database objects may be affected!
  14. It's early and I'm probably just missing something obvious, but it's confusing me... if (! $stmt = $db->prepare($sql)) { print_r($db); //echo "Error=". $db->error."<br />"; //$msg = "SQL failed -".$db->error; print_r($db); } The above code is intended to trap a failure in a prepare and give me something meaningful out of it. BUT the output (abbreviated) I get from this is... mysqli Object ( ... [connect_errno] => 0 [connect_error] => [errno] => 1146 [error] => Table 'warehouse.BinType1' doesn't exist [error_list] => Array ( ) ... mysqli Object ( ... [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) ... So even simply doing a print_r on the $db object is causing the error to be cleared. Even stepping through on debug shows that when I arrive at the (commented out) echo statement or the second print_r - the values have been cleared. The $db object is from a straight forward new mysqli() and it works for most things I've tried so far. So I thought I'd ask for some enlightenment and in the meanwhile I'll fix the SQL causing the error :-/ Thanks
  15. Firstly - you should be using either mysqli or PDO - mysql_query is outdated and should be your first thing to remove. The main thing about SQL injection is to not directly put the user entered string into a SQL statement, both mysqli and PDO support bind variables. This allow the statement to have a place holder and effectively the value is linked to the statement in such a way as to stop SQL injection attacks.
×
×
  • 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.