Jump to content

Phi11W

Members
  • Posts

    163
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by Phi11W

  1. Lots of good alternatives, but here's the basic problem with your code. You're creating a new tr ("Table Row") element for for every item so yes, they will appear on separate rows. Try creating a "tr" before starting the loop, then add a pair of "/tr", "tr" elements after every fifth item, and remember to close the last row after the loop. Regards, Phill W.
  2. How about something altogether simpler and more user-friendly: <a href='www.11.com'>ABC</a> <a href='www.22.com'>ZXC</a> <a href='www.33.com'>CCC</a> No need for "error messages" at all. Only give the Users options for things that they're allowed to do. "What's the best way to prevent someone from shooting themselves in the foot? Don't give them a gun in the first place!" Regards, Phill W.
  3. $row1 is an associative (keyed) array containing the data returned by your SQL query. That's a good enough "store" for this context. If the "if" is misbehaving, then you need to find out what values it's [not] working with. This is the fundamental core of "debugging" your application - getting in amongst the code and seeing what's going on. The var_dump() and print_r() functions are your friends here. $row1 = mysqli_fetch_assoc($result1); var_dump( $row1 ); if($row1['accountType'] == 'Student') . . . Regards, Phill W.
  4. String Comparsons in PHP are case sensitive. Is idNum a number or not? If it is, then the value passed in $user should not appear in quotes. Doing so forces MySQL to perform an implicit Type Conversion, which can cause some nasty side-effects. Better still, use a prepared statement to pass the parameter value; that will protect you better from SQL Injection attacks. No need to do this in two successive queries. Let your Database do the Joining: select u.courseCode , m.field1 , m.field2 , m.field3 , ... from user_info u inner join module_details m on m.classListCourseCode = u.courseCode where u.idNum = ? Never use "select *" in Production code. Regards, Phill W.
  5. An alternative is to encapsulate this logic into a Class that represents a Player. You would populate an instance of this class from a database query and the class contains a method that handles this name formatting for you - with the advantage that it willthen be consistent for any Player. class Player { function __construct( ... ) // Probably from a database query { $this->forename_ = ... ; $this->surname_ = ... ; } function __toString() : string // Simplifies debugging { return $this->formatName(); } // Here's the encapsulation of the name-formatting logic // Write it once, use it many times! public function formatName() : string { return sprintf( '%s-%s', $this->forename_, $this->surname_ ); } public function forename() : string // Simple property retrieval { return $this->forename_ ; } public function surname() : string // Simple property retrieval { return $this->surname_ ; } private string forename_ ; private string surname_ ; } Regards, Phill W.
  6. The error happened on line 36 of the file "index.php". That may or may not be in the slab of gigantic code you posted. $this is only valid inside [instance] methods of a class. Regards, Phill W.
  7. "Danger, Will Robinson!" Your suffering from [Evil] Type Coercion here. $_POST variables are all Strings. Feeding them into the date() function forces PHP to parse and convert the given String value into a Date value, which can have some very confusing consequences. More importantly, though, your quoting is messing things up. PHP doesn't understand the "smart"/sloping quotes that seem to have their way into your Post, so I'm assuming you're not really using those. 🙂 Double-quoted strings have variables inside them expanded. Single-quoted string do not. $x = '10' ; if ( '10' === "$x" ) => true because $x is expanded into the value '10' if ( '10' === '$x' ) => false because '10' != '$x' So, your first call to the date() function really is trying to make a date out of the String value '$fromdate'. Lose the quotes to pass the value of the $fromdate variable. You should never trust User input, so you should be explicitly parsing the POST'ed String values to make sure they represent sensible Date values, and then pass the resulting Date values into the date() function. Regards, Phill W.
  8. Roles are hooks that you can hang permissions off. Users are just Roles that can log into the database. "Cluster" is just PostgreSQL-speke for the PostgreSQL "instance". Nothing to do with multiple machines or multiple databases. Databases are .. well .. databases. Schemas are logical subdivisions of databases, but not widely used, in my experience. Not at all. You can have many, many Roles, all doing different things, all in the one database or across many databases. All of the settings above are there for PostgreSQL itself to work. Let well alone. Read up on the Host Based Authentication file and how it works. Getting this wrong can leave your database wide open to attack. Start adding your own rules to allow access for you and your Application. host all all 1.2.3.4/32 md5 # Application Host host me all 2.3.4.5/32 md5 # development machine As requinix quite rightly says, that's removed all authentication from connections matching that Rule. Quoting from the Documentation: Personally, I'd say never user "trust" in the pg_hba.conf. Regards, Phill W.
  9. One of the elements submitted with the POST request should be the name attribute of the clicked [submit] button. Some of your buttons have the name "out". Some of your buttons have no name at all - they should all have one. None of your buttons have the name "inside", which your PHP code is testing for. Regards, Phill W.
  10. Since the two tables have no fields in common, I assume you want a linking table ("Weak Entity") between the two, something like this: create table employee_attendance ( empno ... , att_date ... , Ot ... , primary key ( empno, att_date, Ot ) , foreign key empno references employee ( empno ) , foreign key ( att_date, Ot ) references attendance( att_date, Ot ) ); I'm guessing at the primary Key for the attendance table here - an employee would attend something ("Ot?") on a given date. Don't use reserved words, like date, for table or column names. Eventually, it will come back to bite you. Regards, Phill W.
  11. My recommendation? Don't do it. $teams is an array of Strings with, I assume, two elements (as in "A v B") so you don't want to restrict the number of elements there. If you restrict the length of the Name Xml element, then you run the risk of losing the second team entirely or even breaking your own code: Arbitrarily cutting this at 25 characters, your code only just gets the ' v ' delimiter that the explode() function requires. If you did the cutting at twenty characters, or if the former name were just two characters longer, then you would lose that delimiter and your code might well break, receiving only one element in the resulting $teams value. $hie->Name = 'Arnold Schwarzenegger v Sylvester Stallone' ; ^ 1 2 | 3 123456789012345678901234567890 I have to ask "why" you want to do this at all ... If your application allows names to be longer than 25 characters, why are you truncating them? I suspect your Users would be less than impressed if they chose much longer names and your code just chopped them off at some arbitrary limit.
  12. It's not a "conflict with the php language" - it's downright sloppy work on the part of your "Developer". People's names have had apostrophes in them for centuries. In more recent decades, programming and markup languages (like PHP and HTML) have used apostrophes to delimit the start and end of things like string literals and attribute values. Your Developer has failed to take into account this conflict between the two usages of this innocuous-looking character (and, indeed, if this data is going anywhere near a Database, the tools and techniques that have also been around for many years that get around this particular problem, specifically Parameterised Queries). Your User might be able to work around this problem by "doubling-up" the apostrophes when entering them into the "back end form" (i.e. type the ' character twice), as in [ O''Sullivan ]. This might at least get the data safely into the Database (if that's where it's going) but won't guarantee that the data will render correctly at the HTML end of things. This could have been a lot worse. Obligatory XKCD Reference: Little Bobby Tables. I would recommend that you acquire the services of someone who actually knows what they're doing with PHP to assist you in this. Regards, Phill W.
  13. the convention around here is "New question, new thread". That allows for short, direct answer to short, direct questions instead of long, rambling threads where all the "Goodness" gets lost. Some comments on the above: the use of "global" breaks encapsulation, requiring the environment "outside" the function to provide the variable. It is better to pass the data as an argument to the function. What value does admin['gender'] have? Any value passed that resolves to true will cause the ternary operator to return "Mr" and everything else will return "Mrs". The code makes no attempt to ensure that the array indexes used actually exist; this may or may not be an issue. What if the individual is female and not married? They might object to being called "Mrs". What if the individual is not gender-identifying? They would object most strongly to be referred to by either of the terms used here. Marital status and/or gender are both Personal Data and should be stored in the User's "record" (whatever form that takes) so that it can be managed by/on behalf of the User and changed over time. Regards, Phill W.
  14. Remember that you're constructing a PHP string that just happens to contain some HTML markup that a web browser can make sense of. Nothing magical is going to happen to the way PHO does that building just because you're building "HTML" (or "SQL"). You must follow PHP Rules for constructing strings and having that "loose" ampersand floating around in the middle, whether or not it's wrapped in braces, just won't work. How about something more like this: printf( '<a href='?page=%d&country=%s'>%s</a>', $page_number + 1, $cleaned_current_page_country, 'Next' ); Regards, Phill W.
  15. This is a remarkably common problem and it's all to do with Data Types: These are Character data and so are sorted alphabetically. "010" < "02" < "021" < "022" < "03" < "031" < "034" What you want is more like these, which are numeric and so are sorted numerically. 2 < 3 < 10 < 21 < 22 < 31 < 34 Somewhere along the line, your predecessor managed to get this value into a Character-based form instead of a numeric one, hence your current difficulties. Regards, Phill W.
×
×
  • 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.