phrants.net
4Fév/100

rSync alternative — Syncing Folders in Windows XP over the network

For a long time now I've relied on batch files and the windows scheduler to run rsync to synchronize my local directory to a network folder. It worked well but I didn't like editing all the settings and having to tweak it for any minor changes. Today I stumbled across SyncToy from Microsoft.  Every now and then Microsoft does something right and then they don't include it as part of the OS. This another fantastic tool that's super intuitive and easy to setup. You simply choose your two locations and then indicate how you want the directories synced. You can even create a shortcut that sends an argument to autorun the sync via the scheduler.

Download it for free from Microsoft's website: http://www.microsoft.com/prophoto/downloads/synctoybeta.aspx

There are a lot of command line programs and some other very technical options out there which are open source, but this is perfect.

Remplis sous: Windows Aucun commentaire
4Fév/100

Apostrophe PHP problem – Putting an ‘ into a mySQL database

You may notice that when you are putting data into your mySQL database from PHP, somehow a magical back slash appears from nowhere. This happens basically because PHP doesn't want anyone inserting malicious code or SQL injections into your database. The slash is there to protect us from our own coding. It appears from nowhere, and it is aptly named "Magic Quotes".  There are a couple of places online that explain how to address this, but it still took me a good few hours to really understand what I needed to do.

.

The first step for me was to get the input from the HTML form that was submitted:

$name=$_POST['name'];

Now, your code checks to see if Magic Quotes is on in your server's version of PHP
If it is, it will remove any of those extra slashes in names like O'Brian which was O\'Brian

if(get_magic_quotes_gpc())
{
$name = stripslashes($name);
}

Now you can use $name as it is in your code to display without the annoying backslash. To make it safe for your database, however, you need one final step. This last bit prepares your variable to be safely put in your mySQL database:

$name = mysql_real_escape_string($name);

I'm still a relative newbie at this stuff and wasn't able to find the above few lines of code just how I needed them. Hopefully they will be of service to you as you learn PHP

Taggé comme: , Aucun commentaire
2Fév/100

PHP – Global Variables / Passing Variables to another page

I was at a total loss when trying to set a variable that I could use from one PHP page to another. The POST and GET functions worked to a point for the basic stuff, but I was quickly outgrowing the introductory course. I wanted to do something like an #include for each page, or to set a global variable that each individual page could access. It was extremely difficult to realize, but I finally figured out that what I wanted to do was to set a Session variable. As long as the session variable is set, you can use it at any time from any of your other PHP pages. This turned out to be incredibly easy:

session_start(); //this goes at the top of each page - it either creates or maintains a session with the server

$_SESSION['user_name']; //creates a session variable and can be assigned to a regular variable

$user_name = $_SESSION['user_name']; //now the 'local' variable is assigned from the 'global'

Session variables are amazing, you can just call on them from out of the blue and they will be there as long as the session is open. Sessions do expire after a prolonged period of time or if you close the browser or call on a PHP function to destroy it.  I had a great "Aha!" moment once I realized that I could assign a variable in one file and easily use it in any other PHP file. I guess this is what happens when you teach yourself PHP from online tutorials.

Taggé comme: , Aucun commentaire
2Fév/100

#1062 – Duplicate entry ‘1’ for key 1

This error kept popping up on me in myPhpAdmin while working with a mysql database. It was driving me up the wall as I didn't want to re-create the table just to assign a primary key and set auto-increment in an empty table. The first problem I noticed was that there was more than one "1" in the table. Makes sense, obviously you can't set the primary key in a column where there are duplicate entries. The second piece of the puzzle, however, was much more difficult to identify. It turns out that myPhpAdmin won't allow you to set auto_increment to a column where there is a "0" (zero) as unique key. I changed the zero to a 999 and then was able to set the auto increment. Then I went back in and manually changed the 999 back to zero. I couldn't find this solution anywhere else online, so I thought I would share it here.