Krehn Solutions

An RSVP PHP Script

Category: News
Published on Thursday, 21 January 2016
Written by Raymond Krehn

I've been terrible about posting on here and I just noticed after all this time that my blog doesn't contain any web-based scripts. I am getting married this fall, so I built a website with a RSVP PHP form for our guests. I'd rather have all our guests in a centralized location than a group of acceptance letters stored somewhere, where I may or may not have an accurate count when the wedding date gets closer.

First, we'll need a form. I have mine located in the rsvp.php page:


<form action="RSVPInsert.php" method="post">

    <tr><td align="right">Full name:</td><td><input type="text" name="fullname" value="<?php echo($_POST[fullname]); ?>"><br></td></tr>

    <tr><td align="right">Email:</td><td><input type="text" name="email" value="<?php echo($_POST[email]); ?>"><br></td></tr>

    <tr><td align="right">Phone: </td><td><input type="text" name="phone" value="<?php echo($_POST[phone]); ?>"><br></td></tr>

    <tr><td align="right">Can you attend? </td>

    <td><select name="attend">

        <option value="yes" name="attend">Yes</option>

        <option value="no" name="attend">No</option>


    <tr><td align="right">How many guests?</td>

    <td><select name="numguests">

        <option value="0" name="numguests">0</option>

        <option value="1" name="numguests">1</option>

        <option value="2" name="numguests">2</option>

        <option value="3" name="numguests">3</option>

        <option value="4" name="numguests">4</option>

        <option value="5" name="numguests">5</option>


    <tr><td align="right">If you have guests, <br>please enter their names:<br></td>

    <td><input type="text" name="guestnames" value="<?php echo($_POST[guestnames]); ?>"><br></td></tr>

    <tr><td align="right">Suggest a song: </td><td><input type="text" name="song" value="<?php echo($_POST[song]); ?>"><br></td></tr>

    <tr><td align="right">A message for Ray and Candice?<br></td>

    <td><textarea name="message" value="<?php echo($_POST[message]); ?>"></textarea></td></tr>


    <input type="submit" name="submit">


I threw everything in a table format so it doesn't look off-centered and weird. I also have a RSVPInsert.php that will capture all of the submitted information:


    // ** MySQL settings - You can get this info from your web host ** //

    define('DB_NAME', 'dbname');      // The name of the database

    define('DB_USER', 'user');       // Your MySQL username

    define('DB_PASSWORD', 'password');  // ...and password

    define('DB_HOST', 'localhost');       // 99% chance you won't need to change this value


    // Connect to SQL

    $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Error connecting to mysql');

    mysql_select_db(DB_NAME) or die('Unable to connect. Try again later. <BR> <button onclick="goBack()">Go Back</button>');


    $email = mysql_real_escape_string($_POST[email]);


    // Validate name

    if (!preg_match("/^[a-zA-Z ]*$/",mysql_real_escape_string($_POST[fullname]))) {

        echo('Your name is invalid. Please go back and try again. <BR> <button onclick="goBack()">Go Back</button>');




    //Validate email address

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

        echo('Your email is invalid. Please go back and try again. <BR> <button onclick="goBack()">Go Back</button>');




    // Validate phone number

    $justNums = preg_replace("/[^0-9]/", '', mysql_real_escape_string($_POST[phone]));

    if (strlen($justNums) == 10) { $isPhoneNum = true;}

    if ($isPhoneNum == false) {

        echo('Your phone number is invalid. Please go back and try again. <BR> <button onclick="goBack()">Go Back</button>');




    // Check for pre-existing email

    $sql = "SELECT email FROM rsvp WHERE email='$email'";

    $result = mysql_query($sql);


    // If email on file, then update with form. Otherwise, create new entry

    $row = mysql_fetch_array($result);

    if($row == 0)



    } else







The above code reviews the data getting submitted. By using mysql_real_escape_string, I can prevent malicious attacks against the database through MySQL injection. Essentially, it's ensuring that no one uses the two dashes "--" or other signs like the equal sign to discover how the query is working. Instead, it will display the actual symbol.

I also have various checks going on: It verifies the email is legitimate (with the @ symbol and a domain name), it verifies the phone number is a 10-digit number even if they use braces or dashes, and I also verify whether or not the name is realistic (no numbers).

I have some other webpage formatting after this section, and in my PHP footer section I have the following code:


     function UpdateData(){ 

        // Define variables

        $name = mysql_real_escape_string($_POST[fullname]);

        $email = mysql_real_escape_string($_POST[email]);

        $phone = mysql_real_escape_string($_POST[phone]);

        $guests = mysql_real_escape_string($_POST[guestnames]);

        $song = mysql_real_escape_string($_POST[song]);

        $message = mysql_real_escape_string($_POST[message]);  


        //$sql="UPDATE rsvp SET fname='$_POST[fullname]', phone='$_POST[phone]', attend='$_POST[attend]', numguests='$_POST[numguests]', guests='$_POST[guestnames]', song='$_POST[song]', message='$_POST[message]' WHERE email='$_POST[email]'";

        $sql="UPDATE rsvp SET fname='$name', phone='$phone', attend='$_POST[attend]', numguests='$_POST[numguests]', guests='$guests', song='$song', message='$message' WHERE email='$email'";


        if (!mysql_query($sql))


            die('Error: ' . mysql_error());



        echo("Your RSVP has been updated!<br><br> - Ray & Candice");




    function NewData(){

        // Define variables

        $name = mysql_real_escape_string($_POST[fullname]);

        $email = mysql_real_escape_string($_POST[email]);

        $phone = mysql_real_escape_string($_POST[phone]);

        $guests = mysql_real_escape_string($_POST[guestnames]);

        $song = mysql_real_escape_string($_POST[song]);

        $message = mysql_real_escape_string($_POST[message]);  


        $sql = "INSERT INTO rsvp (fname, email, phone, attend, numguests, guests, song, message)

                VALUES('$name', '$email', '$phone', '$_POST[attend]', '$_POST[numguests]', '$guests','$song','$message')";


        if (!mysql_query($sql))


            die('Error: ' . mysql_error());




        $attend = $_POST[attend];


        if($attend == "yes")


            echo("Thank you! We look forward to seeing you!<br> If you need to many any changes, just use the same e-mail address and fill out the form again.<br><br> - Ray & Candice");

        }else {

            echo("Sorry you can't attend. We hope to see you soon!<br><br> - Ray & Candice");





In the If statement of the first batch of code, it's looking for an email address. If an email address is in use, then their entry in the database is updated. If an email address hasn't been used, then it adds a new entry.

Since the number of guests attending and whether or not a person is attending the wedding are pre-filled, I determined there was no purpose behind the mysqL_real_escape_string for these two scenarios. Since the user cannot manipulate them, I can use the values directly from the $_POST[] command. 

Finally, to get this working you need to create a table structure in MySQL:

  • fname (text)
  • email (text)
  • phone (text)
  • attend (text)
  • numguests (int)
  • guests (text)
  • song (text)
  • message (text)

Set email as unique identifier. This is important because the entire table is based off this field. 

All columns but numguests should be text with a maximum character count of 100. I can't imagine too many people having a name more than 100 characters. The numguests column should be an integer.

That just about covers it!

Cutting Television

Category: News
Published on Friday, 09 October 2015
Written by Raymond Krehn

I've had a television service ever since I was a little kid. I remember when I had an antenna on top of my box that we called "bunny ears." Yes, the television was a large box with ears. We had to adjust the antenna once in a while to get clear reception, or the channels would get some fuzz or be gone completely with white noise. The problem was that some of the channels would be clear and others would not. If I wanted to see another channel, I would go up to the television and change the channel by a knob. I may have had to adjust the antenna again to get a picture. We knew something was on a channel at a certain time through TV Guide. It's still around today, but it's all digital. It was similar to a magazine, and it had ads throughout so you knew what the latest and greatest shows were.

At some point in the mid-90's, we upgraded to a cable-based television. I think the only reason we got it was because both of my parents were employees at AT&T, and it was offered for a major discount, if not free. Of course, Comcast eventually bought that part of AT&T. We had a television with a remote control by this time with a box provided by AT&T. We were able to see the latest shows through a digital guide. It was very useful, and there were plenty of channels to watch. 

Why am I telling this story? As long as I can remember, television has been the default method of entertainment. I got to the point where I had hundreds of channels with Comcast through their service. I also tried Dish Network and even subscribed to the newly offered Century Link Prism television. I loved the DVR feature, but I still question why they still sell optional HD channels. Shouldn't that be a requirement this day in age? While those service providers are good, except Comcast, the price is no longer justifiable. Hundreds of channels provided and how many do I watch? Maybe 3-5 channels? They don't offer an "a la cart" that I want. I just want some local channels like the Altitude channel to watch the Colorado Avalanche. Denver Broncos are typically on CBS4 or NBC. I may also want ESPN, Fox Sports, FX, Discovery, and History. 

I've realized that a lot of the shows I want to see on any of the channels above are either on Netflix, Prism, or Hulu. Sure, they may not be same-day or even same-year as the releases, but they all make it somewhere. Amazon Prime is a yearly fee of $100 that is worth it. I shop a lot online since I hate stores, so the free-shipping is a no brainer. Netflix costs $10/month and offers thousands of shows. I have a "to watch" list that grows faster than I watch the shows. I hate Hulu for various reasons. Yet, I find myself paying roughly $100 for television service on a monthly basis. It's time I cut the wire.

Smartifying my Television

We have a some-what smart television with a Sony Bravia. A smart television is one that connects to the internet and has applications like the services I mentioned above. The quality is decent, but the connection frequently dies with any service. My first step to cutting the wire was to find some device that could make our television even smarter. I found a few options:

  • Roku - I like the idea, but I didn't want to deal with another controller. Still a possible option for the future as it supports all three major services
  • A game console (Playstation 4 or XBox One) - Didn't want to spend $400 on a streaming device. I just don't have time for games as I used to.
  • Chromecast - $35 price tag and I can use my phone or tablet as a remote to select a show and watch
  • Apple TV - Same as Roku, but I'm just sick of Apple everything. I feel like it has limited options for services.
  • Boxee - Viable option, but I just want a plug-and-play. I deal with enough technical stuff at work
  • Amazon Fire TV - A good option, but they're competing with Netflix so it's not available, and it's my preferred service.


There are several others, but these are the biggest players. I went with the Chromecast because there seems to be many more services available for it. Other services I liked such as CrunchyRoll (for anime) and Crackle were available. I could also stream from my Chrome webbrowser if I found streams of videos. I'm not completely satisfied with my Chromecast, however, but it mostly fills the void. Another factor in this decision was the support for NFL Gamepass and NHL GameCenter.

Watching Live Sports and Recording

Some streams don't work properly, and I can't seem to get NFL GamePass to stream. NFL GamePass is a $99/year service that allows you to watch football games on any device in either the full game without commercials or in a condensed 40-minute game. I love this feature, but the one device I want to watch games on, my television via Chromecast, doesn't seem to work properly. Their technical support seems to be unable to help me now that I have several tickets open and no responses for over two weeks.

Then I realized that if I wanted to watch Football that I didn't even need NFL Gamepass except the occasional game not on publish television. I recently discovered that various television networks still send signals through an antenna. Shocked, I decided to scan for signals where I live. About 30 channels showed up. The major sports channels are NBC, CBS, and Fox. Guess who has strong signals? It's strange to think that I'm going back to using technology from two decades ago.

I did further research and discovered that not only are antenna channels still available, but their quality is quite good. In fact, they're far superior to cable or satellite HD television. Why? Encryption and compression. Companies like Comcast will encrypt channels to prevent people from stealing television services. This encryption requires a specific device that can decrypt the signal, which is the major reason they have a digital receiver. It's also another method they can earn your money, because only their device is compatible with their services, and you're paying a monthly fee on it. They also compress the signals for service to reduce bandwidth, something they seem to be complaining about lately and why there are data caps. With antenna television, the signals are produced at 100% without any encryption or compression. 

 I had to see it to believe it. There are multiple options including outdoor and indoor antennas. Outdoor antennas will often provide more channels, but indoor antennas work very well too. I also determined that I needed an antenna with an amplifier too, which boosts signals and reduces noises. I narrowed down to two:


I ended up with the Winegard FL-55YR since it was slightly cheaper. The next thing I needed was a device to read the signal. I missed the features of DVR, so I had to find a device that would allow me to record games, shows, or whatever if I wasn't at home. I found the following:


The Channel Master is probably the best of them all for price and value. The more expensive models and the ones with subscriptions have a channel guide that goes up to a week. They take advantage of internet technology to see what shows are upcoming for the future. The cheaper models will only have information for the next 24 hours since their data is received through antenna signal. Some of the more expensive models include various apps or their own channels built-in. Regardless, I went with Mediasonic for $35 since it offered what I needed, and it can read more media files than the other cheaper models.

The Setup and Verdict

The Winegard antenna was very flat, almost like cardboard paper, only with a little electronic device (amplifier) at the bottom. I wondered how this could receive a good signal. After discovering where all the signals were coming from (link above), I found that most of them were North. Using Google maps, since I'm not good with directions, I found that the North-facing wall is right next to our main television. Perfect! I  plugged the cable from the antenna into the Mediasonic and turned it on. I took the paper-ish antenna and held it up to the wall and scanned for channels. They were unbelievably crisp and clear. A football game was on, and I was astonished at the quality. For comparison, I went back to my CenturyLink Prism on the same channel in HD and the antenna picture clarity was indeed better. 

I setup an extra external harddrive I had lying around and formatted it to NTFS, the recommended format by the manufacturer. I plugged it into the Mediasonic, and it recognized the harddrive immediately. I hit the pause button to see what would happen, and I saw a "setting up timelapse" screen. Then it proceeded to record that show. I could view it later by clicking the usb button on the controller. I tried setting up a recording for a later time, and that worked well too. An hour show will take about 4 GB of data, and the Mediasonic supports up to 1 TB (about 1,000 gigs) of data. However, you can setup both the recording and your television to work at different resolutions. I set the Mediasonic to view in 1080p. 

What I don't like is that it records on what you're watching. You can't record a show and watch something else unless you use a different device like the Chromecast. I could record the football game while watching a movie on Netflix, for example. Another thing I don't like is the lack of a 30-second skip button or a reverse button. I can fast forward up to 4x or reverse up to 4x, but I can't just skip periods of time. I'm wondering if I can alter the code for the controller in the software to accomplish this. 

Overall, I'm pretty happy with my choices. I spent the past two weeks testing only the Chromecast and NFL GamePass. Since Amazon's FireTV is competing with Chromecast, we'll have to use the television's built-in Amazon to watch their shows. Almost everything we watch is on Netflix, however. The antenna setup I have is working pretty well, and I think it will be good enough to cover my sports. I know there are sites online that allow you to stream games if they're not available. I will end up cancelling NFL GamePass since their customer service hasn't been helpful, and I can watch the games through my setup anyways. 

{jcomments on}


Category: News
Published on Thursday, 13 August 2015
Written by Raymond Krehn

Note: Recommendations are at the bottom if you want to skip this article.

I came across an easily one-sided article that states in the opening statement, "The use of ad-blocking software is exploding and is projected to cost websites nearly $22 billion in lost advertising revenue worldwide this year, according to a new study." Without going into semantics about the definition of cost, what this article should really state is that ad-blocking software projects to reduce potential revenue by $22 billion worldwide this year. The key difference here is the costs haven't incurred yet and it's only potential income.

I can understand the problem from a business perspective: You provide free content for users and you need to pay the bills and ad space will help pay your bills. It's simply logic. Even Mozilla, the developers behind Firefox have stated that they plan to implement ads in their browser to help pay the bills. But, we also need to consider the users too. Take a look at Denver Post, for example. I won't link there, because I will spare you the pain with a screenshot.


Denver Post with Ads

Let's get one thing straight: Denver Post is a news site. Why is 90% of the page that I open up ads unrelated to news? Let alone I have zero interest in guns. The problem, my dearest business industry, is you. I have no problem opening up a website and seeing an ad on the corner of a site. I can see it. It's definitely there. implements this very well. What I don't want to see is my example above. When you're ruining user's experience then you are to blame on your lost revenue. In fact, it is so bad that a study done at Simon Fraser University notes "Computers running the Adblock Plus browser extension saw a 25.0% decrease in associated total data usage during web-browsing sessions." That's excluding videos. Including videos, "testing revealed a 40.0% decrease in total data usage." 

We're beginning to live in a world with bandwidth caps for data. Comcast has a limit of 250gb per month, and many cell phone companies like Verizon and AT&T are much worse with an average data limit of 2GB. 25% reduction of data usage is half a gig that could be better used for streaming music or using maps to help you get unlost. 

Until the industry listens to the user, I highly recommend ad-blocking software. But, my reasons for utilizing it go far beyond bandwidth usage. Many sites that have advertisements don't even know what their own ads are displaying. They're using various vendors like Google Adwords to select ads for them. Let's take a look at one below:

Malware ad

A user captured this on a popular site called Dailymotion, a video-sharing service similar to Youtube or Liveleaks. The ad seems legitimate at first. It informs you that you have spyware detected on your computer and clicking that big button it will help remove it. Instead, it will install malware on your computer. The spyware it was referring to is itself. 

Furthermore, you have dynamic pricing where some sites will alter prices based on varying data such as your personal spending habits, your location, your age, and more. I can attest to this personally. For a flight for two in early July I was given a quote by Southwest Airlines for $537. I didn't purchase the tickets immediately because I wanted to confirm various factors in the decision. About an hour later I went back to purchase the tickets and they had move up to $780. At first I thought it was a supply and demand thing so I checked on my phone. The price on my mobile phone was slightly more than the first price, but not much. The article I linked to about dynamic pricing talks about the pricing differences on Amazon depending on location. Needless to say, it's unfair for the consumer to be judged based on their search history or any of these other factors.



Using one of these options or all of them will drastically improve your webbrowsing experience. Happy browsing!


{jcomments on}