PHP mysqli example – search MySQL database table using a function

In the following PHP program I have accessed the MySQL database (using PHP’s object oriented mysqli extension ) by a PHP function generated by me, and fetched a “MySQL database table” column value (Departments column) based on some key value in another column ( Serial ). To get the required value from database you have to just call a function like this : function getDepartmentName( $dbTableName, “Serial”, 2, “Departments”) where Serial and Departments are two columns of same database table, and 2 is the value in the Serial column in a record. If you dont know PHP MySQL – visit our PHP MySQL programming online coaching classes

Say if you pass the Serial = 2, you will get the corresponding column value of Departments column = ARCHITECTURE, which is located in the same record in the database table, but in different columns. Don’t worry whole table structure shown below.

You should have SQL query knowledge to understand the following code . To get it done you have to call the function like this mentioning column “Serial”, database table name $dbTableName & value in Serial column which is 2 here and $returnColumnName = Departments here Continue reading “PHP mysqli example – search MySQL database table using a function”

Add custom menu, Add theme locations & register new menu

A WordPress developers guide / tutorial – for adding custom menu in new wordpress theme, add one or multiple new theme locations for the custom WordPress menus, so that menu can appear in those places. Register new menu items. Enable your new wordpress theme to add custom user defined nav menus from the admin dashboard. Continue reading “Add custom menu, Add theme locations & register new menu”

Password protecting WordPress Page / Post in which you need to enter password every time

Password protecting WordPress Page or Post : in which you need to enter password every time.

The Problem is : I have set a password for a  page/post in my wordpress blog. I need to ensure that the information should be protected by a password. Normally if you enter a password its kept by the browser cookies. So you don’t need to re-enter passwords. But if I don’t want that. Then what- if I need to re-enter password for each visit..???? Continue reading “Password protecting WordPress Page / Post in which you need to enter password every time”

How to create wordpress plugins: tutorials

I have found the following WordPress tutorials very useful for the beginners to write a plugin in WordPress. Here few plugins tutorial has been listed below. You will be able to build simple contact forms in WordPress after reading one, another tutorial will guide you to change the administration section and login page logo etc. Just go through them and enjoy… Continue reading “How to create wordpress plugins: tutorials”

WordPress Plugin installation in Ubuntu asking for FTP connection info

Probably this problem don’t arise in Windows system, but arises in Linux, and I have faced this problem in Ubuntu 12.04.4 LTS. I tried to install demo-data-creator.zip plugin located in my Home folder. I opened the WordPress Dashboard in browser. Gone to-

Admin section -> Plugins -> Add New -> Upload, then click CHOOSE FILE button, click INSTALL NOW.

WordPress Plugin installation in Ubuntu asking for FTP connection info:

When I am trying to install a plugin in WordPress , it is asking for FTP connection information like the following

wordpress-plugins-installation-problem-in-linux
wordpress-plugins-installation-problem-in-Ubuntu-linux

The solution:

A solution has been described in this page.

The steps to connect MySQL database with PHP

The steps to connect MySQL database with PHP with simple PHP code example.

  1. Connect the server
  2. Select the DB
  3. Write theSQL query
  4. Execute the query & get the resultset / query output in a variable $result.
  5. If resultset contains greater than 1 record the process each record of the recordset by a while loop

<?php

$MYSQL_HOST = “localhost”;
$MYSQL_USER = “bikram”;
$MYSQL_PASS = “bikram”;

$MYSQL_DB_NAME = “eworkshop”;

// connect the server
$server = mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS) or die(“MySQL server connection error : “.mysql_error());
echo “server connected<br />”;

//connect the DB
mysql_select_db( $MYSQL_DB_NAME , $server) or die(“”.mysql_error());
echo “db connected<br />”;

// execute query
$query = “select vehicle_name from vehicle_table“;
$result = mysql_query($query) or die( mysql_error());

if(mysql_num_rows($result) > 0)
{
echo “<table><tr><th>vehicle name</th></tr>”;

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo “<tr><td>”.$row[“vehicle_name”].”</td></tr>”;
}
echo “</table>”;
}
?>