-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
.htaccess example (modify the list of file extensions to suite your needs) - <IfModule mod_headers.c> # Force no caching for dynamic files <FilesMatch "\.(php|htm|html)$"> Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </FilesMatch> </IfModule>
-
You should only put your code onto a live server once it is completely tested. You will waste a huge amount of your time, constantly uploading code just to see the result of each change. Dynamically produced pages, where each request for the same URL can contain different content, should output headers that prevent caching. There are many ways of accomplishing this, but it should be done globally in a .htaccess file or similar so that you don't need to do it in your code.
-
What type of value is in $day ?
-
@nethnet, your description was fine up to the point of mentioning UNIX_TIMESTAMP(). Your query won't work because the NOW() function is a DATETIME value, not a unix timestamp. You can compare a DATE data type with CURDATE() directly. You would compare a DATETIME data type with NOW()
-
Your date format is ambiguous. That could either mean April 11th of next year, December 4th of this year, or April 12th of this year. To a computer trying to sort it, it means April 11th of next year, because the 12, being the left-most digits, is the most significant field (the year part of a date) and the 11, being the right-most digits, is the least significant field (the day part of the date.) A mysql DATE format is YYYY-MM-DD for several reasons, the most important being that it can be directly compared using greater-than/less-than comparisons, which also means that it can directly be sorted. You need to use a DATE data type to hold your event dates in the database. You can convert your existing format into a YYYY-MM-DD value either using php code or you can use the mysql STR_TO_DATE() function directly in your queries. You can format a YYYY-MM-DD value back into your format when you retrieve the value using the mysql DATE_FORMAT() function directly in your queries.
-
Change all the short opening php tags <? to full tags <?php Also, change any short-cut php/echo tags <?= to <?php echo The programmer who wrote that script got caught using the lazy-way short open tags and they should never be used, especially in code that is intended to be distributed to others since there is no guarantee that the server supports the short open tags.
-
session_register() was depreciated nearly 9 years ago. You should be setting and testing $_SESSION variables. You also need a session_start() statement before any output is sent to the browser, which is likely why the page you are redirecting to is not seeing someone as being logged in.
-
The page you are redirecting to upon a successful login is probably redirecting back to the code you have posted and shows an empty $_POST array at that time. Your server likely has output_buffering turned on, which allows the header() redirect to 'work' but is discarding the the output form the print_r() statement when the redirect takes place. Temporarily comment out the header() redirect in the code you have posted so that you can see what is happening when your form submits to it. If output_buffering is on, you should turn it off so you can really tell what your code is doing.
-
You have also just repeated the same blocks of html over and over, so of course you get the same value over and over.
-
Your table name is enclosed in single-quotes, thereby making it a piece of string data, rather than a table name.
-
enctype="multipart/form-data" is only used when you have a type='file' upload field in the form.
-
Your UPDATE query is AND'ing the contents of your `description` field with the value in '$title' and storing that in the `title` column - SET title = '$title' AND description = '$description' The SET term is a comma separate list of column = value pairs. AND is a logical operator.
-
If you use a HTML array name for the form elements, you can eliminate almost all of your code and simply iterate over the values using one simple foreach() loop - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays
-
Quantified Results Based on A few Variables Help!
PFMaBiSmAd replied to imperium2335's topic in PHP Coding Help
count(*) as QTY - counts the number of rows in each group and makes that count available using the alias QTY GROUP BY partNumber, jobType, newUsed - consolidates the rows having the same partNumber, jobType, and newUsed value into groups, first by partNumber, then by jobType within each part number, then by newUsed within each job type. -
Quantified Results Based on A few Variables Help!
PFMaBiSmAd replied to imperium2335's topic in PHP Coding Help
You are making this about 18 times too hard (you have 18 times more code than you need.) Assuming you want to do this first by part number, then type, then condition, the following query should (untested) group and count the information the way you want - SELECT supplier, partNumber, newUsed, jobType, directIndirect, currency, vat, total, count(*) as QTY FROM pourbaskets WHERE enquiryRef = '$enqId' AND supplier = '$sSup' GROUP BY partNumber, jobType, newUsed ORDER BY partNumber DESC -
The error means that your mysql_query() failed due to an error. You can use mysql_error() to find out specifically why, but in your case it is because you haven't selected a database. The 4th parameter of the mysql_connect() is NOT the database name, it is a flag that determines if a new connection should be formed. You either need to use mysql_select_db to select a database to use or you need to specify the database name in the query.
-
http://www.php.net/manual/en/types.comparisons.php
-
Either use gmdate or set the date.timezone setting (see the date_default_timezone_set function) to be the time zone you want.
-
It's called the Ternary Operator. Scroll down to Example #2 at this link - http://us3.php.net/Ternary
-
When you have a set of related values, you would generally use an array and use a foreach(){} loop to iterate over the array. Here is an example for producing (and validating) checkboxes that would equally apply to generating a select menu - http://www.phpfreaks.com/forums/index.php?topic=329432.msg1550587#msg1550587
-
For the specific code you posted, there's no reason to use a loop to optionally create 15 different variables, just to put them into a hard-code HTML <select> menu. Just simplify all that to make the <select> menu all at once - <?php $select = "<select name='timelimit'>\n"; for ($i=1; $i<=15; $i++) { $selected = ($timelimit == $i) ? "selected='selected'" : ''; // determine which choice is selected or a default value of an empty string $select .= "<option value='$i' $selected>$i</option>\n"; } $select .= "</select>"; echo $select; ?>
-
The error is still occurring on your live server, but either the error_reporting or display_errors settings are set to hide them. However, your server is probably still logging them, thereby creating multi-gigabyte error log files. Code should not generate ANY type of errors during its normal execution. Only for abnormal things, such as a hacker attempting to break into your script or a legitimate visitor doing something perfectly valid but that your code did not take into account. You would want to log errors due to these type of things, but you wouldn't want to have to sift through millions of error messages to find them just because every time your code runs it generates dozens of error messages.
-
Your need to test, using some error checking logic in your code, if your queries executed without error before you can use mysql_num_rows(). If your query failed due to an error of some kind (returned a FALSE value instead of a result resource) you need to handle the error and report/log information about the error so that you can find and fix it. You need to - 1) Generate and output a 'user' message, such as 'Sorry, an error occurred and the requested operation cannot be completed!' 2) Generate a system error message containing the query that failed and the reason why it failed (other information such as line number and file name) and then use trigger_error to log and/or display the error information, depending on your display_errors and log_errors settings. The use of reserved words that Maq pointed out would have resulted in sql syntax errors and having some error checking and error reporting/logging logic in your code for the mysql_query() statement would have show you.
-
Total beginner plea for help - Formmail.php
PFMaBiSmAd replied to Headshot's topic in PHP Coding Help
Also, by putting arbitrarily entered (from the form) email addresses into both the To: and From: fields, you are likely triggering your mail server's relaying restrictions and it wants your script to authenticate against a valid mail box hosted on the mail server before accepting the email. When either (or both) the To: or the From: field is a valid email address @your_domain and hosted on the sending mail server, you are satisfying the most commonly used relaying restrictions. When the To: address is your mail box on the sending mail server, the mail server will accept an email from php running on your_domain and/or when the From: address is your mail box on the sending mail server, the mail server will accept an email from php running on your_domain. -
On a live server, display_errors should be OFF and log_errors should be ON. You want to log the errors so that you know what is going on and can find and fix whatever is causing them. On a development system, display_errors should ON. Error_reporting should always be as least E_ALL or even better, it should be a -1