Tuesday, November 19, 2013

Dowloadable link File Upload without Refreshing (Reloading of Page)

http://tuts.wtfdiary.com/2012/06/file-upload-in-php-without-refreshing.html

Friday, November 8, 2013

URL parameters value encryption/decryption using MD5 to Authenticate value stored in database field

You can create a hash of the id so you get something like:
 
http://www.demo.com/displaycommittees.php?id=81dc9bdb52d04dc20036dbd8313ed055

In you db query you can do a select on the users table including a WHERE statement that also hashes the id column like:
 
WHERE MD5(id) = $_GET[id]

A side note to this is that MD5 hashes do not necessarily have to be unique. So you cannot be sure that this select statement is always returning the row you wanted. 

This works fine and i have always applied this algorithm. for instance assuming the actual value of the encrypted id 23, if you try to put 23 in place of the encrypted code it will not work( no result will be display).

Thursday, November 7, 2013

HOW TO REMOVE THE COMMENTS (LEAVE A COMMENT) IN WORDPRESS PAGES



STRAIGHT TO THE POINT

Step 1: Login into Wordpress as Admin.

Step2: Under Appearance Section, Click on Editor.

Step 3: Look to your extreme right under Template and Click Page  Template (page.php).

Step 4:  Look for  <?php comments_template(); ?> and uncomment it like this <!-- <?php //comments_template(); ?>--> that is all.

Step 5: Then Click on Update File to complete the process, go back to your page and refresh.

If you know this Article or post helps do comment.

Monday, November 4, 2013

HOW TO DE-ACTIVATE THE WORDPRESS ADMIN-BAR




Step1: Open the WordPress Folder/Directory
Step2: Open the wp-includes folder/Directory
Step3: Open the admin-bar.php file and uncomment the following lines out as seen below.
/*if ( is_user_logged_in() ) {
                                // Add "About WordPress" link
                                $wp_admin_bar->add_menu( array(
                                                'parent' => 'wp-logo',
                                                'id'     => 'about',
                                                'title'  => __('About WordPress'),
                                                'href'  => self_admin_url( 'about.php' ),
                                ) );
                }

                // Add WordPress.org link
                $wp_admin_bar->add_menu( array(
                                'parent'    => 'wp-logo-external',
                                'id'        => 'wporg',
                                'title'     => __('WordPress.org'),
                                'href'      => __('http://wordpress.org/'),
                ) );

                // Add codex link
                $wp_admin_bar->add_menu( array(
                                'parent'    => 'wp-logo-external',
                                'id'        => 'documentation',
                                'title'     => __('Documentation'),
                                'href'      => __('http://codex.wordpress.org/'),
                ) );

                // Add forums link
                $wp_admin_bar->add_menu( array(
                                'parent'    => 'wp-logo-external',
                                'id'        => 'support-forums',
                                'title'     => __('Support Forums'),
                                'href'      => __('http://wordpress.org/support/'),
                ) );

                // Add feedback link
                $wp_admin_bar->add_menu( array(
                                'parent'    => 'wp-logo-external',
                                'id'        => 'feedback',
                                'title'     => __('Feedback'),
                                'href'      => __('http://wordpress.org/support/forum/requests-and-feedback'),
                ) );*/
Step4: Save then Refresh you site that is all.

Thursday, October 24, 2013

How to Delete(Unlink) a file from a Folder/Directory Using the file name from MySql Database Table

Hi PHP Programmers, my name is Moses, i stumble into a typical problem when i was working on a particular project and i tried to figure out how to delete a named file from a folder/Directory. After much research i was able to come out with a solution by writing out this snippet( few lines of code to delete a file from a folder). 

I will carefully comment or describe each line of code for a better understanding and if you feel link asking any question or feel link commenting please do feel free. 

<?php

// CONNECTION TO MYSQL SERVER

$hostname_conn = "localhost"; // assign server localhost to variable $hostname_conn$database_conn = "smf";       //assign assign database smf to a variable  $database_conn$username_conn = "root";       //assign server username root to a variable $username_conn$password_conn = "root";       //assign server password root to a variable $password_conn
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR); // assign the full connection string path to a variable called $conn

mysql_select_db($database_conn,$conn);
$query = "SELECT reportpdf FROM bills WHERE id = '$_GET[del]'";
$result = mysql_query($query) ;

//$num=mysql_num_rows($result);
if ($result && isset($_GET['del'])){
$row = mysql_fetch_assoc($result);
$target= $row['reportpdf'];
@$pdffile = $target;
unlink($pdffile);
}
? >


Vivid Explanation of the above Code
I will start by explaining from the line of code after the connection string to MySql database server with the variable name $conn. i guess the comment above is self explanatory.

mysql_select_db($database_conn,$conn);
     This line of code send a signal to the the database   $database_conn through the connection string $conn. here the database is expose for you to  use the table there in. that means you don't have to border yourself about accessing the database with a username or password since you have done that with the connection string above.
Note (TIP):  

mysql_select_db :- This is a function that enable you to root the database(Select the database from mysql server.

$database_conn:- This is a variable already declared above now representing the database name instead of using the physical database name.

$conn:- This is a variable already declared above now representing the connection string to the mysql server(granting the user a successful connection).

$query = "SELECT reportpdf FROM bills WHERE id = '$_GET[del]'";
    This line of code is the SQL(Structure Query Language), which select the database table field reportpdf from the database table bills querying for the value of the field reportpdf using the primary key field id against a URL Parameter $_GET[del]

Note (TIP): 

$query:- This is variable assigned with the SQL statement "SELECT reportpdf FROM bills WHERE id = '$_GET[del]'"; that means instead of calling this full line of code you just make do with the variable $query that is all.


$result = mysql_query($query) ;
   This line of code execute the query using mysql_query() function
and assigned it value to a variable called $result.



if ($result && isset($_GET['del'])){
$row = mysql_fetch_assoc($result);
$target= $row['reportpdf'];
@$pdffile = $target;
unlink($pdffile);

}
  The above line of code is a conditional statement that check for for the existence of some set parameters inorder to execute the a set of instructions. for instance see below.

if ($result && isset($_GET['del'])):- This help to check of the query is true $result and the URL Parameter $_GET['del'] has a valid value then do the execute the following lines of code and delete the file from the folder.

{
$row = mysql_fetch_assoc($result);
//define a specific row in a table$target= $row['reportpdf']; // assign the reportpdf field value to a variable called $target
@$pdffile = $target; // assign $target to another variable called $pdffile
unlink($pdffile);
// unlike() function enclosing the variable $pdffile will remove the file from the folder with the name found in the reportpdf file

} 

Note (TIP):
During the uploading of the file to the folder the folder name and the file file name was save along in the table (bills) field reportpdf like assetbills/phpdocument.pdf that is why i didn't concatenate the directory or folder with the file expected file name contained in the variable.

I guess this will help and if you benefited from this code do comment. thanks.

Tuesday, October 22, 2013

How to re-enable JSP support in Dreamweaver and add the latest MySQL Connector/J.


Although I don’t really use Adobe Dreamweaver for web development (although if i’m doing interface design where I need a quick way to alter and view CSS changes fast I do) a friend of mine the other day (who uses Dreamweaver heavily) wanted to know how to re-enable the old JSP (Java Server Page) support in Adobe Dreamweaver CS 5 as Adobe removed the JSP support in Dreamweaver CS4 (I believe, may be a slightly older version they removed it however.)
A couple of months ago I developed a secure members system for him in Java (JSP’s and some Java Beans too) using my favourite IDE… NetBeans, he  however wanted to make some visual changes to the JSP files and likes to use the ‘Live View’ mode in Adobe Dreamweaver CS5, so I found out how to re-enable this functionality (although not officially supported by Adobe) and so thought I’d share it here and also explain how to add the latest MySQL J/Connector to be able to work in Dreamweaver as he needed that for the ‘Live View’ too.
To re-enable ‘JSP support’ in Adobe Dreamweaver
  • Open up the Adobe Extentsion Manager
  • Click on ‘Install‘ (to install a new plugin)
  • Browse to and select the following file: “C:\Program Files (x86)\Adobe\Adobe Dreamweaver CSx\configuration\DisabledFeatures\JSP_Support.mxp” and ‘Install‘ that extension.
  • …your done, open Adobe Dreamweaver and your good to go!
To add the MySQL J/Connector for Adobe Dreamweaver
Unlike running your Java web application on Tomcat or another Java application server such as GlassFish etc. Dreamweaver looks in a certain place in the Dreamweaver folder to get its plugin’s to work within Dreamweaver, so when developing with Dreamweaver and JSP and if you rely on a MySQL database (or any other Java libraries for example the IBM DB2 database driver etc ) you’ll need to add these to the folder ‘JDBCPlugins’ in the Dreamweaver folder on your system otherwise you’ll probably see an error message like so:-
“org/gjt/mm/mysql/Driver” class not found
So lets begin…
  • Firstly download the latest MySQL Connector/J from MySQL here: (http://www.mysql.com/downloads/connector/j/), at the time of writing I downloaded (mysql-connector-java-5.1.18.zip)
  • Extract the JAR (Java archive) file named ‘mysql-connector-java-5.1.18-bin‘ from the downloaded archive to “{Dreamweaver Folder}\Configuration\JDBCDrivers\“.
  • Re-open Adobe Dreamweaver and you should now be able to use the MySQL JDBC driver in Adobe Dreamweaver.
I hope this has been helpful to some peopl.
Do Leave a comment if this helped you out....

Wednesday, July 24, 2013

Dynamic populating the drop down list based on the selected value of first list (Cascading Dropdownlist) Self submission

HOW TO BEGIN THIS SIMPLE PROJECT

  • Create the folder job in your htdocs directory or wwwroot directory
  • create a file with the name test.php inside the job directory
  • create a folder inside job directory, call it connections where you will create the file conn.php containing your database connection string. so create the file conn.php inside the connections folder/directory.
  • lastly copy and past the below code in the file test.php, save it and you are done.
  • lastly test the project by simply opening any of the explorer and type this 
  • http://localhost/job/test.php.

THE INPUT FORM (test.php)


  THE INCLUDE FILE conn.php

create the file conn.php inside the folder called connections that is connections/conn.php. do change your database username and password to based on your server configuration eg apache server

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conn = "localhost";
$database_conn = "jobglo";
$username_conn = "root";
$password_conn = "root";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
?>

 

 

THE FORM SCRIPT (test.php)

copy and paste this code on your editor and save with test.php
<?php require_once('Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_conn, $conn);
$query_rstate = "SELECT  DISTINCT stateid, state FROM `state` order by state asc";
$rstate = mysql_query($query_rstate, $conn) or die(mysql_error());
$row_rstate = mysql_fetch_assoc($rstate);
$totalRows_rstate = mysql_num_rows($rstate);

$colname_rslga = "-1";
if (isset($_GET['stateid'])) {
  $colname_rslga = $_GET['stateid'];
}
mysql_select_db($database_conn, $conn);
$query_rslga = sprintf("SELECT DISTINCT lga,lgaid, stateid FROM lga WHERE stateid = %s", GetSQLValueString($colname_rslga, "int"));
$rslga = mysql_query($query_rslga, $conn) or die(mysql_error());
$row_rslga = mysql_fetch_assoc($rslga);
$totalRows_rslga = mysql_num_rows($rslga);
?>
<?php
require_once('connect/conn.php');


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<SCRIPT language=JavaScript>
function reload(form){
var val=form.stateid.options[form.stateid.options.selectedIndex].value;
self.location='test.php?stateid=' + val ;
}
</script>




</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="200" border="0" cellspacing="3" cellpadding="3">
    <tr>
      <td>State:</td>
      <td><label for="stateid"></label>
        <select name="stateid" id="stateid" onchange="reload(this.form)">
          <option  value=  <?php if (!(strcmp("", $row_rstate['stateid']))) {echo "selected=\"selected\"";} ?>>Select One</option>
          <?php
do { 
?>
          <option value="<?php echo $row_rstate['stateid']?>"<?php if (($row_rstate['stateid']==$_GET['stateid'])) {echo "selected=\"selected\"";} ?>><?php echo $row_rstate['state']?></option>
          <?php
} while ($row_rstate = mysql_fetch_assoc($rstate));
  $rows = mysql_num_rows($rstate);
  if($rows > 0) {
      mysql_data_seek($rstate, 0);
      $row_rstate = mysql_fetch_assoc($rstate);
  }
?>
        </select></td>
    </tr>
    <tr>
      <td>LGA</td>
      <td><label for="lga"></label>
        <select name="lga" id="lga">
          <option value="">Select One</option>
          <?php
do { 
?>
          <option value="<?php echo $row_rslga['lgaid']?>"><?php echo $row_rslga['lga']?></option>
          <?php
} while ($row_rslga = mysql_fetch_assoc($rslga));
  $rows = mysql_num_rows($rslga);
  if($rows > 0) {
      mysql_data_seek($rslga, 0);
      $row_rslga = mysql_fetch_assoc($rslga);
  }
?>
      </select></td>
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($rstate);

mysql_free_result($rslga);
?>

CREATE A DATABASE CALLED jobglo and create the two tables below with the data below