PHP threw a weird T_PAAMAYIM_NEKUDOTAYIM token

While working on a Scientific Calculator PHP code recently, I accidentally stumbled on some weird sh*t. This is the first time I encountered a strange error message. The token says T_PAAMAYIM_NEKUDOTAYIM. I was like… the hell is that?

T_PAAMAYIM_NEKUDOTAYIM

PHP did, however, try to give you an idea of what this error message is all about by adding the message, expecting ‘:’ or ‘;’, which gives us a hint that the error has something to do with these operators. Upon further research, I was able to find out what T_PAAMAYIM_NEKUDOTAYIM is all about and what it means.

T_PAAMAYIM_NEKUDOTAYIM is actually a Hebrew word for twice or double (Paamayim) colon (Nukudotayim) – פוקאים נוקדותיים, it can be found in PHP’s Manual, among the list of tokens. Normally, the double colon is a token use to allow access to static, constant, and overridden properties or methods of a class (see Scope Resolution Operator (::)), but if use in a wrong statement, it results to the Paamayim Nekudotayim error message. Since I was using a switch function for the PHP code I was writing, I was using colons :, serving as an operator that marks the start of the case’s function. Perhaps, somewhere along the lines, I accidentally entered a double colon. PHP was smart enough to detect that I wasn’t trying to get a class property so it threw an error instead. However, sometimes, this is not the case. Missing operators could result into PHP thinking that you are using a double colon by accident.

I tried replicating the error message by intentionally adding double colons into the cases, but it threw a different error instead. Until finally…


The code in line 20, default:: triggered the unexpected T_PAAMAYIM_NEKUDOTAYIM error message. Now, I understand that it is not the accidental double colon that’s triggering the message, but rather, the missing class method. By using ::, PHP was instructed to access a class but since it cannot find it, it threw out this message. According to this resource which I found in Wikipedia, there are several instances that will result in calling out this message.

Perhaps, we could consider this as one of the Easter Eggs hidden in PHP, perhaps not. But there is a history why this strange message is included in PHP. The name “Paamayim Nekudotayim” was introduced in the Israeli-developed Zend Engine 0.5 used in PHP 3. It remained in PHP, even in PHP 7, although some developers complain that it can be confusing for those who don’t speak Hebrew and were suggested that it should be changed into something else.

There are other weird things hidden in PHP, Eric Wastl mentioned a few in his site PHP Sadness.

Site Stats and Archive.Org Donation

Site Stats
Hello guys, I’m happy to announce that this portfolio and web resource site seems to be booming lately, as evidenced by the site stats above. I started this website back in May 2018 and in just 4 months time, it manages to reach the 1k hits milestone. Way back then, it just got like 1 unique visitor, sometimes 0, and oftentimes that 1 visitor also happens to be me. Anyway, the site was meant to be my portfolio, but since I wished to share whatever I learn and have, I also turned it into a web resource site, offering Desktop Wallpapers to download, introducing cool applications, teaching how to do some stuff, and well, sharing my codes to help aspiring programmers.

Over the months, the site received a rise and drop in number of visits, ranging from 0 to 10, sometimes, 10-40, and maybe if I recall correctly, the highest was around 100+, but that wasn’t constant until this month of July when one of my posts was suddenly indexed by Yahoo! and Bing (formerly MSN Search/Windows Live Search/Live Search) and was showed in the top 1 spot. This skyrocketed my hits from a mere 10-20 to 200+ in a day (up by 1000%), and it grew up to 800+ following Google‘s crawl that had them associating my site with some keywords (I’m yet to determine what keyword though). My hits fell to 400+ in recent weeks, and once again, it gained momentum this week. This time, it reached the 1000 mark, with my best at 1,220 at the time of this posting. The only disappointment I have though is that the keyword that propelled my site was not the one I was aiming for. In short, my site’s boom was just an accident (luck) and not because I was good in SEO.

Brewster KahleAside from the site stats, I also would like to announce my support for Archive.Org (also known as the WayBackMachine or The Internet Archive). It was founded by Brewster Kahle, an American Internet entrepreneur, internet activist, advocate of universal access to all knowledge, and digital librarian, who also happens to be the creator of Amazon’s Alexa website. The Internet Archive is funded by the US Government and by donations. It’s mission is to make the internet free. For now, I donated 5 bucks, and maybe in the following months, I will be donating more. I encourage others to do the same. You can donate here.

Learning how to use PHP to connect and manipulate MySQL Database

Sadly, my study has stalled for awhile as it was spent on Game Designing that SMBX game I created for the kids. Anyway, going back to studying, so far I have learned how to create an IV Drip Rate Calculator, a multiplication table using for loop, solve project Euler’s first easy question, use PHP to store data via Super Global Variable $_SESSION, and now I wanted to learn MySQL and how to use PHP to connect and manipulate MySQL’s Database. And using, mmtuts tutorial videos, I was able to understand and learn how to program MySQL to create a database and manipulate its tables using this tutorial.

Recently, I came upon mmtuts few videos that revolves around PHP and MySQL interaction, and I have compiled them on this post so that we don’t have to search them on YouTube anymore. I am going to apply this knowledge into practice, posting my notes here in case I forget them. Well, the thing about programming is that you need to keep on practicing them, otherwise, you’ll forget and you may have to start reviewing them all over again. After weeks of hiatus, I feel like I don’t know anything about PHP and that I might need to start from the very beginning, but thank god, I kept my notes on this blog. Now all I have to do is walk through them so I could remember. Anyway, going forward…

MySQL Fig1
One of the couple things I did recently was create a MySQL database with PHPMyAdmin in localhost. Unfortunately, I haven’t included that tutorial in this blog yet so I couldn’t insert any reference as to how to setup a localhost server in your PC, as well as setup PHPMyAdmin. For that tutorial, you may have to reach out to Google using this link. Now, assuming everything is setup properly, what I did was activate and launch PHPMyAdmin. It should open in one of your browsers. On PHPMyAdmin’s console, I created a new database named altometa. In order to do that, click on New at the Side Menu, then enter a database name (in this case “altometa”) in the Database page, and click on Create button. Now that we have a database, I went on to the SQL menu, which opens up the query command page. Next, I entered the following commands:

CREATE TABLE DBUsers (
    uid int(11) not null PRIMARY KEY AUTO_INCREMENT,
    first_name varchar(256) not null,
    last_name varchar(256) not null,
    email_ad varchar(256) not null,
    rank varchar(256) not null,
    passkey varchar(256) not null
);

INSERT INTO DBUsers (first_name, last_name, email_ad, rank, passkey)
	VALUES ('Anthony', 'Y', 'altometa@altometa.com', 'Admininstrator', 'admin');

To learn and better understand what I did, go to this tutorial. Technically, the command is sending an SQL query to create a table name “DBUsers” (will be turned into all lowercase “dbusers”), with columns for uid, first_name, last_name, email_ad, rank, and passkey. Int means Integer so for the uid, MySQL will always treat its content as an integer. Varchar is the type that tells MySQL to treat the characters as string. All of them should not be empty (thus not null), and uid should be used as the PRIMARY KEY and will automatically increment by 1 every time a new set of data is entered.

The next set of command lines (INSERT) will access first_name, last_name, email_ad, rank, and passkey, entering the values “Anthony”, “Y”, “altometa@gmail.com”, “Administrator”, and “admin” into those columns in the same order.

Now that we have a database with a primary user, we can begin creating PHP files. But before anything else, it is also important to set up a user account that has all the privileges over the entire MySQL databases. By default, there is username “root” that has no password but has all the privileges over MySQL, which was explained by mmtuts in his tutorial videos (first video). In my case, I decided to create another username “altometa”. In order to do that, go to PHPMyAdmin’s main dashboard, then select User accounts in the menu. In the User accounts page, there is a link called “Add user account”. Click that and the next page should be pretty self-explanatory. Enter a user name, select host name “Local” which will automatically set localhost in the Host name’s field, enter a password, retype password, activate all privileges by checking Global privileges, and under SSL, keep it at REQUIRE NONE then hit “Go” button.

As for the PHP side, the first thing I did was create a folder “includes” within htdocs (XAMPP). After that, I created the PHP file db_inc.php inside “includes” folder with the following content:

<?php

$dbServername = "localhost";
$dbUsername = "altometa";
$dbPassword = "admin";
$dbName = "altometa";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

So what does it mean? Well, it’s telling PHP to connect into the database server, which in this case is localhost since we are using local. And I will be connecting into it using the User account “altometa”, with the password “admin”, then access database table name “altometa”.

Note that each MySQL query we do in PHP requires us to access MySQL, that is why we have to create this PHP file so that we could easily call it without having to type the code each time we create a query.

Well, this is it for now as I am rather running out of time. I actually did other PHP files a few weeks ago, those are PHP files that allows you to search the database, and insert data into the database. I will probably be developing them and will add them here next as well as explain how they work.

Working on Super Mario Gaea Game Designing Project

Working on Super Mario Gaea Game Designing Project

Super Mario Bros X Project GaeaFor the past several days, I’ve been working on a game designing side project, supposedly made for two special kids. It’s a Super Mario game, an episode for Super Mario Bros X, a Super Mario Game Engine made by fans that allows you to make a custom Super Mario side-scrolling game. Think of it as Super Mario Maker, only that this game engine has been out even before game maker was released. It has all the important elements of the original Super Mario Bros 1, 2, 3, and World, it also includes graphics and npcs from other Nintendo games like Metroid and Legend of Zelda, furthermore, it can be customized.

About Project Super Mario Gaea

Super Mario Gaea is an episode for the fan game Super Mario Bros X. It’s not intended to infringe Nintendo’s intellectual rights, it’s just a fan game, and while not officially approved by Nintendo, the game company doesn’t care about it as well. I intend this game to include all elements of the originals, namely, Super Mario Bros 1, 2 & 3, Super Mario World, and the New Super Mario Bros game series. The game can be played in 2-players using the characters Mario and Luigi.

The powerups include that of the mentioned Mario series, including, the classic Red Mushroom that makes Mario grow in size, the Fire Flower that allows him to shoot Fireballs, the Ice Flower that allows him to throw Ice balls that freezes enemies, the Penguin Suit, the Frog Suit, the Tanooki Suit that transforms Mario and Luigi into a Tanooki, the Power Leaf that transforms Mario to a Raccoon, the Hammer Suit and some other custom powerups.

The World Map should be a hybrid of Super Mario Bros 3 and Super Mario World. It also allows usage of World Items — powerups you can store in your inventory. The map has the traditional SMB 3 stages, castles or fortresses, the Mushroom houses that allows you to gain lives or powerups, a game house that allows you to play side games, and a wiseman house where you can get secret information. Each world has a Big Boss at the end. Most levels also have Star Coins to collect, and a secret Power Star. It also packs with hidden exits and secret stages. There are probably around 10 worlds overall with each world having its own theme. For instance, World 1 is Mushroom Land, and most of the stages are filled with Mushrooms.

Final Word

When I was young, I always fancy myself to be a game designer. I would take some papers and draw my stage. With this game engine, that dream came true. Unfortunately, the game will probably take months to a year to finish, depending on how busy I am, but if ever, it will definitely be posted here on my blog. I’m also planning to create a blog for this project so I could post the updates and update everyone interested to play it when it’s complete.

A Challenge from Project Euler (Question no. 1)


Late Post! But this is really something worth adding into the blog. About 2 weeks ago, I met a developer who introduces me to Project Euler, a website that has some really difficult mathematical problems that’s bound to test not only your math skills but your programming skills as well. He challenges me to answer one of the problems. One of them is Problem no.1, which goes something like this:
==================================

Multiples of 3 and 5

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

==================================
See, first problem and it already sent me sweating and breaking some neurons! So the challenge goes like this, we need to find the sum of all the multiples of 3 or 5 for the numbers below 1000. For example, multiples of 3 includes 3, 6, 9, 12, 15… while multiples of 5 are 5, 10, 15, 20, 25… below 1000 means it should be up to 999 for multiples of 3 (ie. …990, 993, 996, 999), while 995 for multiples of 5 (ie. …980, 985, 990, 995). Now we have to add the multiples of both 3 and 5, so it goes like this: 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25… and up until …990, 993, 995, 996, 999. That would be 3+5+6+9+10…

Now, we are ask to build a program in any language that does the equation. Earlier, this developer friend of mine by the name of Mike suggested that I use Python because it’s much easier, then I told him I am more comfortable with PHP, so I went to solve it in PHP.

I was able to build this code…

<?php
for($x=3, $max=1000; $x <= $max; $x++){
	if (($x % 3) == 0) {
	echo $x;
	}
}

?>

and

<?php
for($y=5, $max=1000; $y <= $max; $y++){
	if (($y % 5) == 0) {
	echo $y;
	}
}

?>

I thought of looping it using the for loop. The instruction is meant to seek for the multiples of 3 and 5. It states that for variable x (y), which is equivalent to 3 (5), set variable $max to 1000, $x ($y) should be less than or equal to $max which is 1000. Increment $x ($y). It’s followed by an if statement that if $x ($y) with a modal value of 3 (5) is equal to 0, then display the looped value of $x ($y). So the preprocessor will start counting from 0 and upwards, if it finds the multiples of 3 (5), it will display it… (result: 369121518… or 3, 6, 9, 12, 15… and 510152025 or 5, 10, 15, 20, 25…) now, I thought of merging the two loops and add their value. But I failed!

Another developer friend of mine who was good at math, came up with a code written in JAVA, which is where is he more adept at, and converted it into PHP. The outcome is:

<?php
$sum = 0;
for($x=3, $max=1000; $x <= $max; $x++) {
    if((($x % 3) == 0) || (($x % 5) == 0)) {
        echo $x . ' ';
 
    } 
}

It’s technically almost the same as my code, but better… he was able to merge both multiples of 3 and 5 and come out with 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30, 33, 35, 36… btw, the || in his code is the operator that means “or”. He used the same variable to produce the multiples of both 3 and 5.

Then he adds all of the values with this code:

<?php
$sum = 0;
for($x=3, $max=1000; $x <= $max; $x++) {
    if((($x % 3) == 0) || (($x % 5) == 0)) {
        echo $x . ' ';
        $sum = $sum + $x;
    } 
}
echo ' = ' . $sum;

He cleverly created the variable $sum to add all of the contents of $x so the loop goes like when it comes up with 3, it adds that into $sum and $sum gets a new value of 3 (from previously 0). In the next loop runtime, it gets 5 then adds that into $sum which already has 3 so it becomes 3+5, and ends up with a new value of 8. The loop continues to do this until it reaches the limit <= 1000, in which from there it will start getting the “false” value and thereby terminate the loop as per its function.

The result is the answer 234168.

I showed it to Mike, but he was not quite impressed. He said, that while our method works, it will fail if we have a bigger $max value, let’s say less than 100,000,000,000,000,000,000. PHP will struggle to process everything and it would take more processing time, if not crash.

He wrote his own method:

<?php
$max = 1000;
function sumOfNaturalNumbers($n) {
    return ($n * ($n + 1)) / 2;
}

$sum = sumOfNaturalNumbers($max / 3) * 3;
$sum += sumOfNaturalNumbers($max / 5) * 5;
$sum -= sumOfNaturalNumbers($max / 15) * 15;

echo $sum;

Brilliantly, he uses the summation notation formula to avoid the intensive resource-consuming process of the for loop. I ask him what += and -= means as these operators seem new to me. He said += will add the value of the variable from the right to the variable to the left. In short, it works like a shortcut for (sumOfNaturalNumbers($max / 5) * 5) + $sum. The same with -=, only this time, it’s subtraction.

He got the idea from StackExchange.com.

He arrived at the answer which is different from ours. His answer is 233833.33333333.

But unfortunately…

When I checked at Project Euler…

I also checked our answer and it seems nobody among us got it right. LOL

OK, it’s not that we are dumb programmers, nor are we poor at math. But it seems we didn’t understood the problem. So, I reanalyzed the problem to figure out why we got the wrong answer. Then I notice that it says “below 1000”. But… we set it to less than or equal to 1000. While multiples of 3 has no problem since the highest it can go is 999, which is below 1000, it’s problematic for multiples of 5 which can arrive at 1000. So I redid the formula.

Using the loop, the problem can be solve by changing the loop statement from $x <= $max to $x < $max so it turns out like this:

<?php
$sum = 0;
for($x=3, $max=1000; $x < $max; $x++) {
    if((($x % 3) == 0) || (($x % 5) == 0)) {
        echo $x . ' ';
        $sum = $sum + $x;
    } 
}
echo ' = ' . $sum;

Unfortunately for Mike’s formula, it takes more than just tweaking the $max variable. I had to set 3 variables and set it all of them to less than 1000.

<?php
$max3 = 999;
$max5 = 995;
$max15 = 990;
function sumOfNaturalNumbers($n) {
    return ($n * ($n + 1)) / 2;
}

$sum = sumOfNaturalNumbers($max3 / 3)*3;
$sum += sumOfNaturalNumbers($max5 / 5)*5;
$sum -= sumOfNaturalNumbers($max15 / 15) * 15;

echo $sum;

And after that, we got this:

How did we arrive at this equation? Using the Summation Notation formula Sum = N*(N+1)/2

Define:

S3 = 3+6+9+12+15+…+999 = 3*(1+2+3+…+333) = 3*333*334/2 = 166,833
S5 = 5+10+15+…995 = 5*(1+2+3+…+199) = 5*199*200/2 = 99,500
S15 = 15+30+45+…+990 = 15*(1+2+3+…+66) = 15*66*67/2 = 33,165

Now, S3+S5 includes all multiples of 3 and 5 but it includes all multiples 15 twice (double-count those).

S3+S5-S15 = 233,168

The correct answer is 233168. I’m the 764219th person in Project Euler to solve the problem. By the way, this problem is just 5% of the highest difficulty level in Project Euler and we already cracked our heads. Oh my god!

Project Euler: A good site to test your programming skills

Project Euler: A good site to test your programming skills

Project EulerJust today, I talk with a programmer friend of mine at lunch time. He asked about how my programming study was going. I told him I was doing well, I am now starting to study databases and how PHP could access it, add entries into it, or modify its records. I also told him that I was also able to successfully create a Multiplication Table in PHP and found an efficient way to do it. He smiled and challenge me, asking me if I could find the answer using programming to a problem where you have to add all of the numbers starting from 1 to 100 (ie, 1+2+3+4+5+6…+100). I proudly answered that it can be done using an increment loop. What played to my mind is using the same formula I did with the multiplication table where I incremented 1 using the looping increment method. I could create numbers that count up to one hundred simply by defining the limit count with a formula of $var = 1, $var <= 100, $var++, which means value of $var is 1, if less than or equal to 100, keep on incrementing. Then, probably by modifying a part of it, I could make it add all the numbers in the loop. But he said that the process in that method would be lengthy since the loop would go on a repetitive cycle that would have to repeat 100x. So he presented me with an alternative method... the alternative? Well he showed me this:

A Sigma? And with variables… I was like, where have I seen this before? It looks familiar… Aha! The summation notation… God dang, I remember this formula in my Statistics class back in College. Who would have thought this could be use in programming as well… back then, when I was studying Computer Engineering, I thought it was insignificant and was just a way of the school to add units so they could “summation notation” their income.

Surprisingly, using the summation notation, you could come up with the answer in seconds using this formula:

summation

Where n is the last natural number in the count. So using the formula, the summation would be:

or 10,100 / 2, which is equal to 5,050.

In PHP, that’s written as:

<?php
$n = 100;
echo ($n * ($n + 1)) / 2;
?>

I was totally dumbfounded, that was indeed very efficient! He also gave me a website where I can test my programming skills, this site is full of mathematical problems that helps you become an efficient programmer. The site is: ProjectEuler.net

Project Euler is a website that has a series of challenging mathematical/computer programming problems that requires more than just mathematical insights to solve. While it is true that mathematics will help one arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems in this website. The purpose of this site is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.

I registered on this site and when I tried some of its problems… shucks! it gave me a headache… you will really be put to the test as you will be given mathematical problems that require you to write a code and utilize it to get a solution. Unfortunately, I wasn’t even able to solve a single problem. It just goes to show how long I still need to go before I could become a very good programmer.

While this is a site not designed for newbies, it could enhance your analytical skills. It’s like taking a calculus class. Freakin’ insane, but imagine exposing yourself to these kind of training? If you make it through, no doubt, you will come out an exceptional programmer.

As of now, I am still trying to figure out how to solve problem no.1. He told me to use Python as it is easier than PHP, but I like PHP and besides, although I did study Python, I only finished up until “Hello World!”. I know I kinda jackrabbit started into PHP, but I already started, it’s a little late to go back… oh well…

Working on a Background Color and Text Color Switching Project

6/13/2018 Update
Hey guys, noob here… ok, so I manage to make some nursing calculators in the last few days, but we all know those are basic stuff kids in high school have probably already been doing so I stepped up my self-study and training class up a bit to something a little more complicated.

In project 2: IV Fluid Drip Rate Calculator (Expanded Version), I made a Background Color Switch in there that changes the background color of the page. It works like a charm until you use the IV Fluid Drip Rate Calculator (the main thing), wherein the background color goes back to default (equivalent to #ffffff otherwise commonly known as White). I left it like that because that wasn’t the main goal of the project, but from that glitch I learned more on how PHP process the submitted values. Of course, without books or teachers to teach me, I am merely learning from observation.

This is what I observed, when you submit the values from the form, PHP processes it one time, then the variables empty. Which means in the next session, those values you previously entered are already gone. So when you use the calculator, and since you can only submit either of the two forms, in this case the calculator, PHP will only process the content of the submitted form (of the calculator). The background color switch didn’t send a new value for PHP to process and there was no value retained from the previous session so that is why the background color went back to default. I was able to confirm this when I did a variable dump, the variable for the background color did disappear on page reload. But of course, it’s common sense, it follows an analogy that if you don’t have a pocket to store your coins then of course you can’t keep your coins and the same logic applies here. My code lacks the instruction as to where PHP should store the values for future retrieval and neither was there a retrieve instruction. Sometimes, this is the problem, we thought computers can think and interact like humans… it doesn’t, at least, not without an AI. We have to provide instructions for it to follow otherwise it would just do nothing. Anyway, I started another project to solve this problem. This time, this project is about Background and Text Color Switching. I replicated the Background Color Switch code from the last project and rewrote some parts of it (or should I say — develop) to make it more efficient and clean.

About a day before, I talk to a developer regarding this problem, he advised me to use cookies to store the values and he generously provided me with a solution, here’s his code: (I’m posting this for educational purposes)

<?php

if (array_key_exists('color', $_POST)) {
    $bgcolor = $_POST['color'];
    setcookie('color', $bgcolor);
} elseif (array_key_exists('color', $_COOKIE)) {
    $bgcolor = $_COOKIE['color'];
} else {
    $bgcolor = 'black';
}

?>
<html>
  <head>
    <style>
      body {
        color: <?= $bgcolor ?>;
      }
    </style>
  </head>
  <body>
    This color is <?= $bgcolor ?>
  </body>
</html>

Unfortunately, I could not make it work as setcookie function seems like it does not get values from variables like in the code above, $bgcolor. It returns an error stating that second value should be a string. I tried to make it work but then I realized that it won’t work anyway if the user’s browser does not allow cookies. So I tried another approach, this time, using $_SESSION global variable and it worked remarkably! I instructed PHP to store the textcolor variable into a Session variable when the form is submitted, so eventhough the content of the textcolor variable emptied after page reload, the content was transferred into the Session variable. After that, I instructed PHP that if Session variable is not empty, then Textcolor should be equal to (or should get its value from) Session Variable. With this instruction, I was able to make use of the two forms without undoing the changes made by one another. However, it still gives me an error. There is an undefined variable in one of my options. I suspect there is a conflict with the variables and I think Session variable should be unset somewhere in the process… I’m still analyzing, but it’s 3am in the morning, so I think I should do this tomorrow.

By the way, here’s my code: (It’s still broken though)

The link for my project is here.

<?php
	session_start();
	if(!empty($_SESSION['textcolor'])) {
		$txtcolor = $_SESSION['textcolor'];
	} else {
		if(isset($_POST['changetxtcolor'])) {
			$selected = "selected=\"selected\"";
			foreach ($_POST['txtcolor'] as $txtcolor );
			$_SESSION['textcolor'] = $txtcolor;
		} else {
			if(empty($_POST['txtcolor'])) {
				$_POST['txtcolor'] = "#000000;\n";
				$txtcolor = $_POST['txtcolor'];
			}
		}
	}
	if(isset($_POST['changebgcolor'])) {
		$selected = "selected=\"selected\"";
		foreach ($_POST['bgcolor'] as $bgcolor );
	} else {
		if(empty($_POST['bgcolor'])) {
			$_POST['bgcolor'] = "#ffffff;";
			$bgcolor = $_POST['bgcolor'];
		}
	}
?>
<html>
<head>
<title>Background and Text Color Switch | Altometa</title>
<meta name="description" content="A simple PHP program that demonstrates how PHP can change the background color and text color of the page using a Dropdown switch." />
<meta name="robots" content="index,follow" />
<meta name="keywords" content="background color, text color, background and text color" />
<style>
	body {
		background-color: <?php echo $bgcolor . "\n"; ?>
	}
	p, form{
		color: <?php echo $txtcolor . ";\n"; ?>
	}
	h1 {
		color: <?php echo $txtcolor . ";\n"; ?>
		text-align: center;
	}
</style>
</head>
<body>
	<h1>Background and Text Color Switch</h1>
	<p>This is a demonstration to show how PHP can manipulate the colors of the background of the page as well as change the color of the texts.</p><br/>
	<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><br/>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">Change Background Color: <select size="1" name="bgcolor[]" required="required">
		<option value="#ffffff" <?php if(isset($bgcolor)) { if($bgcolor == "#ffffff") { echo $selected;} else { echo "";}}?>>White</option>
		<option value="#000000" <?php if(isset($bgcolor)) { if($bgcolor == "#000000") { echo $selected;} else { echo "";}}?>>Black</option>
		<option value="#ff4500" <?php if(isset($bgcolor)) { if($bgcolor == "#ff4500") { echo $selected;} else { echo "";}}?>>Red Orange</option>
		<option value="#ffb6c1" <?php if(isset($bgcolor)) { if($bgcolor == "#ffb6c1") { echo $selected;} else { echo "";}}?>>Peach</option>
		<option value="#008080" <?php if(isset($bgcolor)) { if($bgcolor == "#008080") { echo $selected;} else { echo "";}}?>>Teal</option>
		<option value="#8db600" <?php if(isset($bgcolor)) { if($bgcolor == "#8db600") { echo $selected;} else { echo "";}}?>>Apple Green</option>
		<option value="#00ffff" <?php if(isset($bgcolor)) { if($bgcolor == "#00ffff") { echo $selected;} else { echo "";}}?>>Cyan</option>
		<option value="#654321" <?php if(isset($bgcolor)) { if($bgcolor == "#654321") { echo $selected;} else { echo "";}}?>>Dark Brown</option>
		<option value="#008000" <?php if(isset($bgcolor)) { if($bgcolor == "#008000") { echo $selected;} else { echo "";}}?>>Green</option>
		<option value="#ff0000" <?php if(isset($bgcolor)) { if($bgcolor == "#ff0000") { echo $selected;} else { echo "";}}?>>Red</option>
	</select>
	<input name="changebgcolor" type="submit" value="Submit" />
	</form>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">Change Text Color: <select size="1" name="txtcolor[]">
		<option value="#ffffff" <?php if(isset($txtcolor)) { if($txtcolor == "#ffffff") { echo $selected;} else { echo "";}}?>>White</option>
		<option value="#000000" <?php if(isset($txtcolor)) { if($txtcolor == "#000000") { echo $selected;} else { echo "";}}?>>Black</option>
		<option value="#ff4500" <?php if(isset($txtcolor)) { if($txtcolor == "#ff4500") { echo $selected;} else { echo "";}}?>>Red Orange</option>
		<option value="#ffe5b4" <?php if(isset($txtcolor)) { if($txtcolor == "#ffe5b4") { echo $selected;} else { echo "";}}?>>Peach</option>
		<option value="#008080" <?php if(isset($txtcolor)) { if($txtcolor == "#008080") { echo $selected;} else { echo "";}}?>>Teal</option>
		<option value="#8db600" <?php if(isset($txtcolor)) { if($txtcolor == "#8db600") { echo $selected;} else { echo "";}}?>>Apple Green</option>
		<option value="#00ffff" <?php if(isset($txtcolor)) { if($txtcolor == "#00ffff") { echo $selected;} else { echo "";}}?>>Cyan</option>
		<option value="#a52a2a" <?php if(isset($txtcolor)) { if($txtcolor == "#a52a2a") { echo $selected;} else { echo "";}}?>>Brown</option>
		<option value="#008000" <?php if(isset($txtcolor)) { if($txtcolor == "#008000") { echo $selected;} else { echo "";}}?>>Green</option>
		<option value="#ff0000" <?php if(isset($txtcolor)) { if($txtcolor == "#ff0000") { echo $selected;} else { echo "";}}?>>Red</option>
	</select>
	<input name="changetxtcolor" type="submit" value="Submit" />
	</form>
</body>
</html>

Reflecting on some recent events (more like ramblings…)


Life has been rough so far… a lot of unfortunate things happen that it’s enough to drive a sane man into insanity… well, to name a few, you get scolded by your boss for failing his expectations, you lost your wife to some jackass who isn’t contented with his own wife and goes on screwing others’ too, then call it TRUE LOVE (what an idiot), but thank god you divorced her (that would remove some weight on your chest), you lost a love one who probably was the first person you saw the moment you gain consciousness… and there might be more… you get fired, you are unable to pay your rent (that’s scary stuff), lose your vision, etc. etc. Seriously, who needs hell when you already have life! Still, you wonder… why are you still here? What kept you going when it feels like the world has been nothing but harsh? You are not sure what, but despite the hopelessness… you just still hope that behind those dark clouds, there’s still a smiling sun whose going to greet you… right! And then… Boo! Surprise motherf–! There goes your hope… Sigh…

But then again… we just have to keep on going, right? Giving up isn’t the answer. I know life’s been hard, but it doesn’t mean that it’s always that bad. Sure things have already turned from sour to bitter that sometimes it makes you feel that opting out is the answer, but no, you still have an unfinished business, you still don’t know your purpose and you won’t find out if you give up, so yeah, just ride the trolley and see where this roller coaster ends…

Well, you’re still pushing… not really trying to find the meaning of life… you’re just doing your everyday job like you always do… now it feels like you’re a zombie, right? Yes! Because you really are a zombie and you need something to bring you to life, and I’m not talking about brains. Ungh… I’m tired… I really need a place for my head… who knows, this would be my last post, and tomorrow I would be gone, but then again, if that happens, thank god, at least I can finally rest, you restless soul, you.

Project IV Drip Rate Calculator

Drip Rate Calc
So a few days ago, I started studying PHP, and now, this is how far I’ve come. Well, not quite in the developer level yet, but I can definitely say we’re making some progress. So what exactly I am building here? Well, it’s a calculator for nursing students to help them get the IV Drip Rate. So far, I’ve only finished one type of calculator, the one that gets the amount of IV fluid to infuse each hour. You can test it here.

I’m still going to add two more calculators in the next coming days. For now, this is all I have. However, writing this code wasn’t easy. It takes more than just echoing “Hello World!” this time. We are now making use of the GET and POST method (courtesy of Jake Wright’s Learn PHP in 15 mins. Tutorial Video for the basics, and the $_POST Method lesson, and Asraf Uddin, who introduced me to the $_GET Method). So, a little explanation why we used the GET method in this program. Well, the one Jake Wright presented in his tutorial was how to call an action from another PHP page. In our PHP code, we only use one PHP page. In order for the action to run in the same PHP page, we need the method GET to serve as the placeholder for the function. Observe the code above… the function of GET is it converts values/data into a query string in the URL, known as URL encoding, which contains both the page link and the encoded information separated by the ? character. The GET method will also run and display the function, in this case, “calcamtinfuse”. Inside the “calcamtinfuse” function is the Isset function. The purpose of this function is to check whether a variable is set or not. In this case, we first have to index the variables otherwise it would be unidentified by the processor and will return a Warning. And since, we are using a numerical value for the forms, we also have to declare that it is numeric and check if it is a valid number. That is what the Isnumeric Function is for. Technically, this is what the code means, when we enter the numeric values into the form and press submit, function “calcamtinfuse” will execute via GET method. “Calcamtinfuse” will index the variables, set it, and check if it is set, then if it is set then run check if the values in the form fields are numerical. If it is numerical then run equation for the amount of fluid to be infuse per hour, else (if condition is not met), such as the form fields are empty or 0, then it will write “All fields must have a value” message.

Starting to learn PHP

Yeah I know… when it comes to developing I’m still a baby so here I am, I’m going to cry about how difficult programming can be… well, for noobs at least. Just a month ago I planned to self-study on a programming language and at that time, with so many programming languages out there, I dunno what to choose… I’m so freakin’ indecisive and I cannot make up my mind. One friend suggested Java, which is batshit crazy for a newbie like me, but he told me that it’s better to start with something hard so that I would be oriented to the difficulty, and so that when the time comes I am going to tackle other languages, and that since I am already used to dealing with the tougher ones, it would make studying these other languages a piece of cake. Another friend disagreed, saying that if you start with the difficult ones, there is a chance that you will get stuck in your study. So I dunno which of them was right, but I have to make up my mind.

A few weeks ago, I installed Python on my PC, an easy-to-learn programming language but just as powerful as the others. I was gonna start learning the language, however, a few days ago, I installed XAMPP (Cross-Platform, Apache HTTP Server, MariaDB, PHP, PERL) on my computer. See? That’s how fast I changed my mind. So it appears the decision went from Java, to Python, to PHP. Ahh… decisions decisions… Anyway, I’m running out of time, I have to learn as fast as I could… so I went ahead with PHP or otherwise known as Hypertext Preprocessor. A program that runs on various Servers, including Apache — the infamous server, and so far, the only one I am most familiar with.

PHP requires, at least a localhost with a server environment, and this is where XAMPP fits it. This application creates a local server on your computer, replicating the server environment required by PHP in order to run. I already installed XAMPP a few days ago, but today, I configured it to make it work on my computer… no one was teaching me… OK… I kinda lied… there’s YouTube as my teacher… Pretty much everything in XAMPP is already pre-configured by default, just leave the SSL (Secure Socket Layer) setting to Listen to HTTP port 443, and have httpd (Apache Hypertext Transfer Protocol Server) listen to default port 80. Next, run XAMPP Control Panel as Administrator so that Windows won’t treat em’ as a hacker gateway and block em’, then have XAMPP’s port settings set to reflect the initial port configurations.

XAMPP Control Panel Port Config

Next thing I know, I was running PHPMyAdmin, creating a database and setting a user and password, but before that I had to create an admin password. For that, I went to phpMyAdmin’s folder (you can find it inside XAMPP’s folder), then edited config.inc.php. Under $cfg['Servers'][$i]['password'] = ''; , I set my password inside the quotations and leave the default user to root. After that, I played around with the database and ultimately crashed it. Eh… noob! But that’s not what I came here for… I could learn MySQL later, and right now, my problem is figuring out how to code PHP and test it. I know for a fact that PHP uses the browser to interpret the output of the commands, I already have XAMPP provide that environment so what’s left to do is figuring out how to open PHP’s output in the browser. OK, so I tried creating a PHP file using Notepad and wrote what noobs usually write…

<?php 
echo "hello world!";

?>

Then I opened it with the browser… Alas! It came out exactly the way I wrote it, it wasn’t processed. It came out raw, LOL. So I was wondering where I should put this php code so that XAMPP would process it. I also tried opening localhost in the browser and calling the php but it gave me an “Object not found” error message. Then after some Internet research, I found out that the file should be put inside the htdocs folder as this is where XAMPP processes the PHP files by default. So I put it in there, opened localhost and tada! My first PHP script came out!

PHP Hello World

Simply put, “Hello World!”, a way of saying “Hello to the World of Programming!” A welcoming sign for noobs…