When I started working on SEO for pages, I noticed something strange occurring with errors stating that redirection or sessions could not be started. Warnings would show up on the top of pages stating that you cannot perform these functions since the headers already started.
This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.
Friday, May 24, 2013
Fixing Buffer Issues
When I started working on SEO for pages, I noticed something strange occurring with errors stating that redirection or sessions could not be started. Warnings would show up on the top of pages stating that you cannot perform these functions since the headers already started.
Tuesday, April 16, 2013
Every Other Row a Different Color
The following code will allow you to change colors every other row in PHP.
Add the following around the do { loop:
$cnt = 0;
do {
$color = ($cnt & 1)? "#F8F8F8" : "#FFFFFF";
$cnt++;
.
.
.
Add the following to the <tr> tag:
<tr style="background-color: <?php echo $color; ?>">
With this example, every other row will be a light grey color and the other row will be white. The first row starts off being white.
Friday, June 1, 2012
PHP Date Time Picker
I found this code that is FREE, but have used it a couple of times in applications where the date is to be asked. I am adding it to the blog here so that we can have access to it if we need to go back and reference some information.
The calendar component written in php script. It contains 2 modes: normal display calendar and date picker.
This is really a great utility and has worked very well.
Tuesday, February 7, 2012
Checking the values of a submitted form
Occasionally you may way to check to see what data is being submitted form a form. I have used this simple little code in the past, and it has help solved mysteries while trying to program. Simply put this code before any section that would save the data to the database and it will display the results of the submitted form to the screen instead of saving it to the database. Just remember to go in and either comment out the code or remove it.
echo "<pre>";
print_r($_POST);
exit();
echo "</pre>";
Saturday, January 28, 2012
Reading a Textarea Field Into Separate Lines
On occasion, you may run into the need to create a small utility the will read each line of a textarea field and process each line separately. I have done this on a few occasions (like the domain upload for YourPopLinks.com or the Quick Task function on DNSTCcontact.com).
Here is the code:
1. You setup a field in your form that is a textarea, let’s call it dataList.
2. On the processing side, you would use the following code:
$dataList = trim($_POST['dataList']);
$dataProcess = explode("\n", $dataList);
foreach ($dataProcess as $line) {
$cleanData = trim($line);
...
process $cleanData
...
}
The first trim will remove the carriage return bit at the end of the data, the second trim within the foreach loop, will remove the carriage return at the end of each line. I have seen examples of this where it used the second trim above, but it does not leave the ability to split the data into the $dataProcess array.
That is pretty much how you do that. Works pretty good.
Monday, January 2, 2012
Formatting MySQL datetime field in PHP
If you would like to get a nice format on the datetime field stored in MySQL, use the following code:
<?php
$datetime = strtotime($row_links['dateAdded']); // The date time field
$formatDate = date("m/d/y g:i A", $datetime);
echo $formatDate;
?>
This will output something like:
01/01/12 8:07 PM
If you want more formatting options for the date(), you can review the manual on PHP.net here.
Saturday, March 12, 2011
Add a day, a week, 2 weeks, a month or multiple days to any date
$date = date("Y-m-d");// current date
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");
Saturday, February 19, 2011
Verification of Delete
Add the following to the section of the page:
<script language="javascript" type="text/javascript">
function verifyDelete(page) {
if (confirm("Are you sure you want to delete this report?")) {
location.href=page;
} else {
return false;
}
}
</script>
To call the function within the page itself, add the following to a link, button, or image:
<a href="javascript:verifyDelete('page_that_does_the_delete.php?key=#')">
delete</a>Now, when the visitor clicks on the delete, a pop-up windows comes up and prompts asking if they are sure they want to delete the information. If they click on Cancel, then it just closes the pop-up and nothing happens. If they click on OK, then the delete program is called and the record is deleted.
Monday, February 14, 2011
Delete All Records in a MySQL Table – Quick Reference
Occasionally you may need to remove all records from a database table to reset the data. The following code is a quick reference to delete all of the records within a table. It can be copy/paste into a PHP page, then it will work after modify the reference to the database and/or tables.
This is just quick reference to remove all records from a database:
PHP Code:
$deleteSQL = "DELETE FROM inventory";
mysql_select_db($database_database, $databse);
$Result1 = mysql_query($deleteSQL, $database) or die(mysql_error());
Adding or Subtracting Dates in PHP
Here is some quick PHP code to add a month to the current date:
$next_month = mktime(0, 0, 0, date("m")+1, date("d"), date("y"));
$outDate = date("Y-m-d", $next_month);For more on the mktime() function: http://php.net/manual/en/function.mktime.php
For more on the date() format function: http://php.net/manual/en/function.date.php
Turning on PHP errors on the Server
By default, if there is a PHP error, it is not displayed on the screen to the user. This is done for security reasons, but it does not aid the programmer in troubleshooting the issue. If you place some code within the .htaccess file, you can turn on the error display. The following code is used to turn on the error display for troubleshooting purposes:
php_flag display_errors on
php_value error_reporting 7
To add this code, perform the following:
- Use putty to log into server.
- cd to the appropriate /home/<users>/www directory
- nano .htaccess
- Copy and paste the code above to the file
- Save the .htaccess file… control/o
If you now refresh the page, you should see the error and you can be off to troublshoot!
Sunday, February 13, 2011
Submitting e-mail to pop-up window
We had an issue with e-mail sending on an ASP Intranet and had to come up with a solution to redirect the sending of mail to a PHP page on the client's website. The client's website did not have access to sendmail or any other program that could be used to send out the e-mail messages.
Solution:
To do this, we had to submit the data to a PHP page using a pop-up window, the only problem this caused was the form stayed on the screen with the entered data after it was submitted, since we used a pop-up window to submit the data.
I was able to solve this problem by adding the following code as an attribute to the form tag:
onsubmit="window.location='newpage.htm';"
This then changes the page that contains the form at the same time it is submitting the data to a pop-up page.
WYSIWYG Editor
The following is the documentation for the WYSIWYG editor that I purchased.
http://www.wysiwygpro.com/index.php?id=56
Thursday, March 19, 2009
Quick and Dirty E-mail Form
The following is some code that will submit whatever fields you specify within the form to an e-mail address.
Place the following PHP code within the body tags, (Note: Your site must be PHP capable):
<?php
if(!empty($_POST)) { // If something is submitted to this page
$body = "";
// This loop will build the body of the message including every variable
while (list($key, $val) = each($HTTP_POST_VARS)) {
if ($key--> "submit") { // Don't include the sumit key value
$body .= "$key: $val \n"; //Add all fields to the message
}
}
$to = "your@emailaddress.com";
$subj = "The subject you want";
$from = "from@websiteaddress.com";
mail($to, $subj, $body, "FROM: $from");
// Display a thank you message after the message has been sent.
?>
<blockquote>
Thank You for your submission. The results were e-mailed...</blockquote>
<?php } else { ?>
<form method=post action=<?php echo $PHP_SELF; ?>>
... Add the form and fields here ...
</form>
<?php } // close the if ?>
Friday, April 18, 2008
Resetting the Auto Increment
You can use the following to reset the key (Or change it to whatever you want):
Perform this after a deletion…
$fixIt = "ALTER TABLE inventory AUTO_INCREMENT = 1";
mysql_select_db($database_experience, $experience);
$Result1 = mysql_query($fixIt, $experience) or die(mysql_error());