Wednesday, September 28, 2011

Clearing DFS Cache

"Server cannot find network path of DFS name space"

Ever ran into that before on a Windows 2008 Server? That is a great error that tells you nothing. Love it. Thanks Microsoft. That great descriptive error from Microsoft means that the cache for the DFS name space is either pointing to the wrong location to is corrupt. Read on to learn how to fix this error....
So your cache is brok-ie no work-ie eh? Here is a quick little command that you can run from an elevated (right click and choose run as administrator) command prompt to "flush" the DFS cache on your local server:

dfsutil cache referral flush

So if you run this from your server right now, it will fail and you will be saying - "What happened???" I did like Bob told me to. That's because you haven't installed the tools that you need on the server to support this command. You need to install the "File Services Tools" on the server. Here's how:

Open Server Manager, under Add Feature, Remote Server Administration Tools (RSAT), Role Administration Tools, File Services Tools

Now close and reopen your elevated command prompt and paste the DFS command in again. Now it should work and clear your cache. No reboot needed.

Here is more information
2008 2003

Wednesday, September 14, 2011

My Favorite "8" Keyboard Shortcuts

Have you ever seen that one "IT" guy that seems to be sooooo fast on the computer that you can't seem to follow him or what he is doing? Next time you see that, pay attention to his hands. I bet they rarely leave the keyboard. I made a decision that I was going to learn to use keyboard shortcuts to accomplish my everyday tasks and I swear it made me faster. I decided to share my top 8 favorite keyboard shortcuts with everyone.

1. Windows key

I love that little Windows key down there on either side of the space bar. That key is so useful to do anything. To open "My Computer" all you have to do is press the Windows key + "E" and BAM there it is. Windows Explorer.

2. Control + an arrow key (either right or left)

You know that you can move the cursor from right to left with the arrow keys but, what if you want to scroll all the way through a line of text. What if I could make it so that you could skip back a word at a time as opposed to a letter at a time. I am here to tell you that pressing Control + arrow key will do just that. Your welcome for the extra time you have to take out the trash and fix dinner.

3. Control + C & Control + V   (Copy and Paste)

An oldie but a goodie. I use this shortcut EVERY DAY - ALL DAY long. I rarely type anything out anymore. Copy and paste baby.

     Control + C = copy
     Control + V = paste

4. F5 (refresh)

Learn to love this key. If you are waiting for an ebay action to end, Facebook to update, or can't wait to read Britney Spears latest F5. That will cause the web page (and other things as well) to refresh and give you the latest content. Use it every where on the computer, not just a Internet Explorer. Love it!!!!

5. Control + A (select all)

How many of us love to click and drag, then just to mess up and have to do it over? I want to copy everything from this folder to that one. Press control + A and it will select it all for you. Then use hint #3 with hint #7 to perform the copy and paste. You hands will never leave the keyboard and you will be shocked on how fast it was.

6. Select + An arrow key (either right of left)

Selecting or highlighting a line in a document is hard to do with the mouse. You have to click and  hold and drag and not too far....go back...wait it jumped to another line. Next time try this; put your cursor on the letter right before the word or phrase that you want to highlight, then press and hold down SHIFT and an arrow key. That will highlight one letter at a time. Then use hint #3 to copy and paste it.

7. Alt + Tab (Move between windows)

Ok folks...time to get real. This is the best tip that I can give you. If you press alt + tab it will switch from window to window (application to application). Say for example that you have a letter you are typing open in Word and you found this great tag line from a website that you want to put there. Here is how I would do it without moving my hands from the keyboard:

Hint #6 - Hold down SHIFT and press the right arrow key to highlight the text that I want from the site
Hint #3 - Press Control + C to copy it
Hint #7 - Press Alt + Tab to move to the Word document
Hint #3 - Press Control + V to paste it

This hint will change the way that you use the keyboard. I can have numerous windows open at the same time and with this hint, I can flip back and forth between applications, making me look like I am flying around on a computer. Use this one to show your boss that you deserve that raise!!!!

8. F2 

Ever wanted to change the name of a document without having to fast now it is opening. Close now I can change the file name. What a pain. Now you can use F2 to rename the file. Highlight (or click once) the name of the file, then press F2. That will allow you to rename. This works in Excel as well, editing the contents of a cell.

Just to prove that it can be done for myself, I typed this whole blog without touching the mouse. Now you can shock and amaze your friends at parties.

Wednesday, September 7, 2011

HTML WebForm with PHP and MySQL - Part 4

Part 4 - PHP Script to insert data into database
Recap: Part 1 | Part 2 | Part 3

Now that we have the database and all of the columns created, we now need to get that data into the database. We can do that with a PHP script.

First we need to build a PHP file that we can edit. Create a new file on your webserver and name it whatever you want (I called mine "pushtodb.php"). Now open that file with your editor of choice. I like notepad++ but you can use whatever is more comfortable for you.

Just like in HTML, we have to open the PHP script with <?PHP (and don't forget to close the tag now so you don't forget later - close it with ?>  ). This tells the browser that you are going to use PHP as oppose to just HTML. 

Lets create a variable to open up a connection to the SQL server. You do that with this command:

     $con = mysql_connect("SQL_server_name","username","password");

Now we have to tell the SQL server which database to use. This command will connect to the SQL server and open up the proper database:

     mysql_select_db("database_name", $con);

Notice the "$con" in that statement? That will take the first statement that we wrote and inject it into this one. Trust me, putting things in variables will make your life a LOT easier as you can reuse the variables throughout the script. 

Time to write that SQL statement that we will actually insert values into the database. Let's make this in a variable named "$sql" so we can use it over and over. At this point (if you read Part 1) you should have all your inputs from your webform in a text file so we can input them in the SQL statement. You have them in notepad++ right??? Right??? Here is the SQL statement; copy and paste this into notepad++ so you can edit it as you need to:

     $sql="INSERT INTO table_name (input_1, input_2, input_3)

Ok we have all the connections out of the way, now time for use to actually perform the command(s). Here is the code that will take all the variables we defined and put them in a IF statement:
     if (!mysql_query($sql,$con))
     die('Error: ' . mysql_error());
One more piece of code that we will need now but will make more sense later on:
      $id = mysql_insert_id ( );
Whew. Come on Bob aren't we done yet? Nope, we have three more steps to finish. 
1. Assign the URL that we want people to go to after the script has been ran
2. Setup the email that will alert us when something has been submitted
3. close the SQL connection
Task 1:  Assign the URL

Put this in a variable, I used the variable "$url" but you can use whatever helps you remember what it is.

     $url = '';

The command that will actually take users to the next page is (look for that variable):

     echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

Task 2: Setup the email

You are going to see variables from above in this one. You can see why variables are important.

     $emailadd = '';
     $subject = 'New contract was submitted';
     $body = "This is the body of the email:";
     $text = $body. " " . $id;

     mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

Pay attention to the bottom line. That is the actual command that will send the email out. As you can see, we are building the email with all the variables we make right above it. See that "$id" variable there. I put that in the email in a future lesson we will use that to lookup this form. We need a place holder that we can call this specific form from the database, and since ID is always unique, its the perfect one to use. 

Task 3: Closing the SQL connection (the easy one)

You are going to find this a real challenge. Here is the code (look for the variable that we assigned earlier):


At the bottom of the script you should see (if you followed directions from above) the ?> to close the PHP script. 

That's it. Post that to your site and give it a shot. Let me know if it works!!!! Good luck.