
Phi11W
Members-
Posts
166 -
Joined
-
Last visited
-
Days Won
13
Phi11W last won the day on March 8
Phi11W had the most liked content!
Recent Profile Visitors
3,490 profile views
Phi11W's Achievements
-
Database connection incl. insert, get update, and delete data.
Phi11W replied to LeonLatex's topic in PHP Coding Help
So build your SQL based on the associative array provided and execute it. If the SQL generated doesn't match the structure of your table, then it will fail - and that's a Good Thing. I'm perfectly happy to have one foot in each "camp" - code and database - and, frankly, I'm a little bit wary of anyone who doesn't. Databases are the ultimate example of Persistence of State and there needs to be a stable relationship between your code and your database schema. I'm sorry, but you need to understand that schema and, if it needs to change, you need to know what that change is going to impact. "Generic" tools, that sit somewhere between the code and the database and try to "do it all for you", do exist - but they can do some really, really stupid stuff if you don't watch them like a hawk. A Database will contain many, many Tables. The mechanism you've created, whilst appealing for single tables, precludes the possibility of using Joins between tables and relational databases just love joins. Regards, Phill W. -
Insert into record where 2 fields must match
Phi11W replied to singingsands's topic in PHP Coding Help
You INSERT new records. You UPDATE existing records. When you do this, you replace the values that were in that record before you updated it. There is no way around this - it's just how databases work. What you're attempting to do is an UPDATE: UPDATE `table` SET field5 = 'value1' WHERE field1 = 'value2' AND field2 = 'value3' Regards, Phill W. -
Using php to display different images based on the date
Phi11W replied to Ocean_Voyager's topic in PHP Coding Help
Just a word of warning - get out of the habit of prefixing numeric values with leading zeroes. That tells PHP that the value is Octal, not Decimal. Try running any PHP code using the "numbers" 08 or 09! https://www.php.net/manual/en/language.types.integer.php "To use octal notation, precede the number with a 0 (zero). As of PHP 8.1.0, octal notation can also be preceded with 0o or 0O." Regards, Phill W. -
I might suggest that it could be because you are jumping between HTML and PHP with appalling rapidity. I prefer to write PHP code that builds or outputs strings that just happen to contain HTML. echo '<select name="YYYY_Entry" style="width:60px">'; if($MM == '1' && $DD < 7) printf( '<option value="%1$s"%2$s>%1$s</option>' , $PreviouseYear , ( ( $_SESSION["DE_YYYY_Entry"] == $PreviouseYear ) ? ' selected="selected"' : '' ) ); printf( '<option value="%1$s"%2$s>%1$s</option>' , $ThisYear , ( ( $_SESSION["DE_YYYY_Entry"] == $ThisYear ) ? ' selected="selected"' : '' ) ); if($MM > '10') printf( '<option value="%1$s"%2$s>%1$s</option>' , $NextYear , ( ( $_SESSION["DE_YYYY_Entry"] == $NextYear ) ? ' selected="selected"' : '' ) ); echo( '</select> ' ); Regards, Phill W.
-
The architecture is completely different. VB programs run on the user's computer and so have access to everything connected to the user's computer. PHP applications run on a web server computer somewhere "out there", on The Web. Your PHP application cannot know anything about any printer, much less interact with them [directly] in any way. To "print" things these days, your PHP application sends document content to the user's web browser (running on the user's computer) and the user can choose to print it from there. For example: https://stackoverflow.com/questions/52410546/create-write-and-download-a-txt-file-using-php Regards, Phill W.
-
You've made the closing of the anchor tag conditional on the user being set. It shouldn't be. Assuming you want an anchor element that lacks its href attribute if the user isn't set, then use something like this: printf( '<a class="custom-btn custom-btn--small custom-btn--style-4"%s>Member Login</a>' , ( ( isset( $user ) && '' !== $user ) ? ' href="https://www.paratuberculosis.com/login.php"' : '' ) ); Personally, I'd omit the whole element, like this, but YMMV: if ( isset( $user ) && '' !== $user ) echo '<a class="custom-btn custom-btn--small custom-btn--style-4" href="https://www.paratuberculosis.com/login.php">Member Login</a>' ; Regards, Phill W.
-
Store date values in Date fields. MySQL knows how to do "date things" with Date fields, including sorting them. It doesn't know how to do "date things" with Varchar fields. Convert your data [once], store it correctly, and wave goodbye to [almost] all your date-related problems. Regards, Phill W.
-
. . . And your question is? Regards, Phill W.
-
php update mysql database with form/checkbox
Phi11W replied to tonypoli783's topic in PHP Coding Help
Short answer: Your HTML is incorrect. You're missing the closing '>' on the Checkbox's input element. I'd also recommend using quotes on HTML attributes. The cases where you need them far outnumber those where you can get away without them. I'd suggest something more like this: echo '<form method="post" action="#">'; while( $row = mysqli_fetch_assoc( $result ) ) { printf( '<center>' . '%1$s %2$t<br>' . '%3%s %4$s<br>' . '%5$s[%6$s] vs %7$s[%8$s]<br>' . '<input type="checkbox" value="%5$s" name="team"> . '</center>' , $row['data'] , $row['time'] , $row['country'] , $row['lega'] , $row['team1'] , $row['pos_t1'] , $row['team2'] , $row['pos_t2'] ); echo '<input type="submit" value="submit"></form>'; Regards, Phill W. -
NOT NULL cannot be omitted if the field must never contain NULLs. Remember that the DEFAULT clause only applies when inserting new records and where this field value is not specified. Including NOT NULL prevents the value from being set to NULL at some later point, i.e. this statement would fail: update .. set quantity = NULL , TYPE = NULL where ... Without NOT NULL, it would work. Regards, Phill W.
-
how to hide data behind the = (page.php?id=xx) for the user
Phi11W replied to wildware's topic in PHP Coding Help
If you're using Sessions (not everybody does) you could capture the given QueryString Argument, save it into the Session, then redirect to the same page without the QueryString Argument, this time taking the id value from the Session. This may go some way to achieving what you want: if ( isset( $_GET[ 'id' ] ) { $_SESSION[ 'id' ] = $_GET[ 'id' ] ; http_response_code( 302 ); header( 'location: .../same_page_without_querystring_arguments' ); return; } if ( ! isset( $_SESSION[ 'id' ] ) ) { // No id available! header( 'location: .../errorpage.php' ); return; } $id = $_SESSION[ 'id' ]; // Display rest of page. Of course, it's not foolproof - anything that can be built can be broken and, at the end of the day, the browser simply has to know this value in order to request it! Regards, Phill W. -
Which field in Charters identifies the driver in question? SELECT chtr.id, chtr.charter_name, chtr.fleet_number, chtr.driver, chtr.customer_name, chtr.customer_number, chtr.dep_date, chtr.status /* \/ \____/ Which of these is the id into the users table? */ , usr.id, usr.fname FROM charters AS chtr LEFT JOIN users AS usr ON chtr.id = usr.id /* \/ Should this, perhaps, be chtr.driver? */ I would expect every table to have its own, unique id field and those ids are completely independent of one another (by which I mean Charter .id=6 is a completely different thing to Users .id=6). Regards, Phill W.
-
What does the fetch() function return? I think you need something more like this: $row = $stmt -> fetch(); echo( $row[ 'N1' ] ); Also, avoid using "select *" in Application code. Whilst you might not have a lot of columns in that table [yet], databases are inherently shared entities and you never know when someone [else] might add a dozen columns full of gigabytes of stuff that this query simply doesn't care about. Always select just the columns that you specifically need. Regards, Phill W.
-
What time does your hosting server (i.e. computer) think it is? That's what the time() function returns and if the clock on your server has "wandered" a bit, you'll get that "wandered" value. If it was out by exactly an hour, either way, I'd be thinking Timezone issues instead. Do you have a working NTP service running on your computer? That should keep your clock properly synchronised with the rest of the world. Regards, Phill W.
-
This is almost always the wrong way to do things. You cannot guarantee that this update process will run every, single day. This is Technology - stuff happens. Updating every record is a lot of [unnecessary] work for your database to do and will, almost certainly, lock the entire table, causing other issues. Showing stuff to Users is not the database's job. You'll write an Application that the Users interact with and that will show them your "remaining time". I'm sorry, but why? Users these days want instant responses, not arbitrary and artificially-enforced delays. If you are interested in a particular date & time, then work out when that is and store that. You never need to change it, "in bulk" or at all, Your application can calculate how long it is until "Real Time" catches up with it and show that duration to the User, no matter what they do in the meantime (refreshing, logging off-and-on again, etc. ), and You can easily tell once you have reached it in a SQL query. Keep it Simple ... Regards, Phill W.