Billy's Blog

To post pictures and other goodies for free on the net.

My Photo
Name:
Location: Utah, United States

Born in Kapiolani Children's Medical Center, just a few blocks from Waikiki. Graduated from Kahuku High School. Rode BMX Freestyle for most of my life (more than 20 years), now my 8 year old son is ripping up the skate parks, but plans on getting drafted by the SeaHawks as a WR.

Wednesday, April 20, 2016

How to deal with "Quotes" in PHP/SQL

Here are the key players:

htmlspecialchars($var)
mysqli_real_escape_string($dbc,$var)
addslashes($var)

$var is the string you are dealing with
$dbc is the DataBase Connection you are using, ie. $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATA) or die('Error connecting to MySQL server.');


Here is the How/Why:
htmlspecialchars($var) changes characters in your string to HTML safe code (" or ' etc)
This allows you to print SQL results to HTML like value="This isn't a "TEST"" without having to change the quotes you use.

mysqli_real_escape_string($dbc,$var) adds a backslash  \  to characters so that the SQL will be read properly as it is entered into the database.
NOTICE: You MUST have the $dbc or it will NOT work

addslashes($var) is basically the same thing as mysqli_real_escape_string($dbc,$var) but not as hard core. If you are only printing to HTML for your own purposes and you know you will only need a few select characters like single and double quotes, this is fine, AND you don't need to remember the $dbc. DO NOT use it to push into a DB, it isn't as reliable


Tuesday, April 12, 2016

Notepad++: Save current session into another

Say you have a session saved in Notepad++ and have since added a number of files. Now you are ready to overwrite the previously saved session with the one you are in now (Might have been switched to "Default") you go up to the "Session Manager" plugin, but there is only "Save Current Session" with no way of saving this one into an old one (Pft! who would want to overwrite an old session with the current one?!? That is preposterous!!) Here is what you do:

  • Save the current one (Default is my goto)
  • Load the old one
  • Click on "Default" (or whatever you called the session you want to save)
  • Select "Load into Current" ("Load without closing" will select automatically)
    • Deselect "Load without closing" if you want to completely overwrite the old session
    • Keep "Load without closing" if you want to combine the old session with the "Default"
  • Hit "Load"
  • Pau


  • Be aware, any changes you do to a loaded session will be saved automatically. If you want to keep the current state of your session (the ability to revert back) you MUST load your session into the "Default" profile. This way your changes will not affect the saved session.