How to make codes work

Let’s face it. We cannot just copy some code from the internet and expect for it to work. Sometimes we need to tweak it to fit our needs.

What I’m going to discuss is about making codes work in a general point of view. So don’t expect that you’ll have the skill to make codes work by just reading this article. Programming experience is actually needed to make codes pulled off from the internet to work. Its not really that easy to make someone else’s code work. It takes time especially if you’re just a beginner.

Here’s what you need to get things work for you:


Programming experience

Doesn’t actually matter if you only know the basics of programming. Knowing the basics is good enough.



If the first one didn’t do good for you. You can do some research. Try googling the bits of code you don’t understand, and know what it does.


Common sense

Yes, common sense is pretty much needed to make codes work. Understand the code. If there is a demo available. Then try it first, so that you’ll know what it actually does. If there is no demo available, then perhaps you can try it on your own. By means of trial and error. That’s what I usually do so that I will know what I’m actually working with.



A good IDE, or Integrated Development Environment is also needed. They say that you will become a lazy programmer if you use an IDE. And I agree with them but there is one advantage that beginners can use to benefit from an IDE. That is to learn and test some code. Since most IDE’s come with intelli-sense feature which predicts what the user is going to type. I recommend Netbeans IDE if you’re into Java. Just try using it so you’ll know what I mean.



After dealing with the syntax errors. You still have to deal with yet another animal. That is logic errors. You need to properly order your code to obtain the result that you want to get. You can make use of an algorithm if you’re having trouble sequencing the codes in your head. A simple numbered list would do if you’re dealing with simple problems.


Ask for help

If ever you’re stuck with something and can’t actually get it to work. Then perhaps its time to ask for help from the experts. There’s always Stackoverflow that you can count on. It’s a community of programmers. Beginners, experts, and masters are all gathered in the community to learn and to help. Just be sure to ask intelligently and nicely though. And don’t ask something that has already been asked. Do some research first on their site by using the (surprise!) search bar. And please don’t ask something stupid. And lastly don’t even think of asking if your english is half-cooked.


Learn more

If my advises above didn’t actually do you any good. Then perhaps you have to enlighten yourself even more. By making use of a tutorial. In the programming language that you’re dealing with. Watch videos on programming. Read then read again.




That’s it for this article. I’m actually a beginner myself. But I care less if I’m really in the position to be telling stuff. But those advises at the top is what I usually do to make codes work. And I think its really effective if you really put your heart into what you’re doing.

Laptop battery equals less processor power

Remember what I said to you about using granola to lessen the processor power when converting from one video format to another?

You can actually achieve the same effect when you’re just running on battery power. The effects are the same and the processor produces less heat. When you compare it to converting videos while laptop is plugged in.

This technique is nice but should not be used everyday. Since it can wear out your battery in no time. The battery lifespan might also be diminished if you used this tip regularly. So be careful.

Turn off display while windows media player is open





If ever you’re wondering how you can turn off the laptop display while windows media player is often. In this guide, I’ll show you how to do it.

You might have tried going to control panel, and selected power options


And tried turning off the display after 1 minute:


But figured out that it doesn’t work since the computer might be thinking that you’re actually watching a video on your computer. And turning off the display would be rude.


First thing that you have to do is to download nircmd. And extract the contents using winrar or any file archiving software.

Open up wmp and select all the songs you want to play.

Copy nircmd.exe to somewhere easily accessible. You can copy it to the desktop if you want.

Then press the shift key on your keyboard and right-click on the desktop. Select open  command window here:


At this point your music should already be playing. If you haven’t started playing it yet. Then play it now, since the monitor will be turned off in the next step.

Type the following commands on the command window that you opened up earlier:


The display should already be turned off by now. But remember that you can turn it back on by moving the mouse.



Turning off the display while playing music can help save electricity or battery. Its always nice to turn off the display if you’re making your computer act like a big mp3 player.

Simple php inventory system

This is the third part of the six part series about creating a php online store.

Here’s a summary of the

Just in case, I haven’t included the download link on the database that were going to use. Here it is. Download that and import it into any database that you have created. Using phpmyadmin.



Item Creation

This would be the form that will be used by the admin to create new products.

Go ahead and type the codes below. Or just copy and paste it into your text editor:

<form action="regprodact.php"  id="info" method="post">
   <h3>Product Registration</h3>
      <label for="prodname">Product Name:</label>
      <input type="text" id="prodname" name="prodname" class="validate[required]">
      <label for="description">Description:</label>
      <input type="text" id="description" name="description" class="validate[required]">
      <label for="reorder">Reorder Qty:</label>
      <input type="text" id="reorder" name="reorder" class="validate[required,custom[onlyNumber]]">
      <label for="bprice">Cost price:</label>
      <input type="text" id="pprice" name="pprice" value="" class="validate[required,custom[onlyNumber]]" value="">
      <label for="sprice">Unit price:</label>
      <input type="text" id="sprice" name="sprice" value="" class="validate[required,custom[onlyNumber]]" value="">
      <label for="category">Category:</label>
      <input type="text" id="category" name="category"/>
<input type="submit" value="create"/>

It’s a good practice not to make the value of the submit button into something like ‘submit’. Because that doesn’t give the user any idea on what he is doing. Most of the time you have to make use of an action word or a verb in the value of the submit button.

Next thing that you have to do is to create a new php file and name it to regprodact.php or whatever form action you have included in the item creation form. What this will do is to insert the data that is inputted by the user into the database.

<?php include('conn.php'); ?>

/* format the text*/
$inserts=mysql_query("INSERT INTO prod_table(PRODUCT, P_DESC, CATEGORY, REORDER_LVL, B_PRICE, S_PRICE") VALUES('$f_prod','$f_desc','$f_category', '$reorder', '$cost_price', '$unit_price')");
    echo mysql_error();


Item list

This will be used by the user to (surprise!) list all the items that matches the query that he is going to type in the textbox:

<form action="listprod.php" method="post">
<label for="items">Item name:</label>
<input type="text" name="items"/>
<input type="submit" value="list">

Create a new php file again, and name it to listprod.php. This is the php file that would produce the results from the user query.

<?php include('conn.php'); ?>
$list=mysql_query("SELECT * FROM prod_table WHERE PRODUCT LIKE '$item%'");
<table border="1">
<th>ITEM ID</th>
<th>COST PRICE</th>
<th>UNIT PRICE</th>
<td><?php echo $row['PID']; ?></td>
<td><?php echo $row['PRODUCT']; ?></td>
<td><?php echo $row['P_DESC']; ?></td>
<td><?php echo $row['CATEGORY']; ?></td>
<td><?php echo $row['QTYHAND']; ?></td>
<td><?php echo $row['REORDER_LVL']; ?></td>
<td><?php echo $row['B_PRICE']; ?></td>
<td><?php echo $row['S_PRICE']; ?></td>


Updating Items

This will be used by the user to update the items that are already stored in the database. You can integrate it with the list item module so that the user can search the items that he is going to update. But of course, I’ll leave that to you so that you’ll also have something to do.

Create a new php file again and name it to updateform.php. This would be use by the user to edit the existing item data that is stored on the database. I’ll leave it as a challenge on how you can connect this module with the list module.

The following are the codes for updateform.php:

<?php include('conn.php'); ?>
$listupdate=mysql_query("SELECT * FROM prod_table WHERE PID='$item_id'"); 
/*You'll have to do the rest here*/

Again, I’ll be leaving you with some challenge. The codes that are supposed to be placed after the comment is similar to the codes used for listing item data. The only difference is that it will only return 1 record. And were going to make use of textbox instead of a table. Remember that a text box should be inside a form tag, and the form tag should have 2 attributes: action and method.


Now, you have to create another php file and name it to whatever form action you have indicated in updateform.php. Here are the codes:

/*Something is missing in this part, I wonder what it is? */
/* format the text*/
$update_item=mysql_query("UPDATE prod_table SET PRODUCT='$f_prod', P_DESC='$f_desc', CATEGORY='$f_category' , QTYHAND='$qtyonhand', B_PRICE='$pprice', S_PRICE='$sprice', REORDER_LVL='$reorder' WHERE PID='$pid'");
    echo mysql_error();


Deleting Items

The last module that were going to create in this tutorial.  I’m getting lazy now, so here’s the query. Remember to do some housekeeping. This is not the full code:

DELETE FROM prod_table WHERE PID='$pid'

Changed my mind. This module should also be connected to the list item module. The most common that people do is to add a delete icon on the table that has the items listed on it. And put a link on that icon to whatever the name of the php file which performs the delete query. Add something like this to your list module:

<a href="delprod.php?itemid=<?php echo $row['PID']; ?>">

<img src="deleteicon.png"></img></a>

Common sense tells us that this link would yield a GET method. So here’s the more complete code on delprod.php or whatever you call it on the link that you have created:

$deletes=mysql_query("DELETE FROM prod_table WHERE PID='$item_id'");
/*do some housekeeping here*/

You might have notice that the parameter for the GET method should be the same as the variable that you have declared on your url. In this case it is ‘itemid’. Always remember that since the code won’t work if they are not the same.



That’s it for the inventory tutorial. Next time I’m going to tell you about the cart. The meat of this six part tutorial series.

Building an online store in php

In this series I’m going to show you how you can create an online store in php. Something like e-bay, or Amazon. But remember I’m just going to show you the basics of creating an online store. Were not actually going to create the next e-bay or amazon.


Things I won’t include

  • Pay-pal integration – I myself have no idea how to integrate pay-pal or any other third party that the clients will use to pay the items that they’re going to buy from the sites.
  • Customized products displayed for clients – We will not be tackling how to display custom products on every client page. If that’s not clear to you, I’m referring to product suggestions. For example, Customer A. Always buys blank dvd’s from the online store. I will not tackle how display the dvd’s on the client page. Something like a shortcut so that the client won’t search for the product everytime he buys from the store. Again, I won’t show you how to do that. But you can do a research and do it your self.
  • Hosting –  I absolutely won’t include this. Since I myself, don’t know how to apply for paid-hosting. And I don’t have a pay-pal account.


Modules were going to create

  • Login system – This would be used by the clients, employees, administrators to login to the system. Privileges for those users will be different from each other. There are limits to what they can do with the system.
  • Inventory– This is would be used by the administrator to determine what products need to be reordered, what products are out of quantity, etc. This also includes managing the product records, updating, deleting, and creating new products.
  • Cart – This will be used by clients to interact with the system. This is the module that they’re going to  use to buy items that are added by the administrator.
  • Purchasing–  This will be used by the administrator to add quantity to products that are below the reorder level.
  • Reports– Will be used by the administrator to gain an insight about what products are sold regularly. And what products are not sold.

On the next part of this series, I’ll discuss about the login system.

Open source software hosting sites

I was about to blog about sites which hosts open source software projects. But then I found this poll on Which contains exactly what I want to blog about. And together with the wikipedia article. So just visit the links below. If you want to know about other open source software hosting sites. Besides the popular