post

A little trick to store data into mysql database from a large form

Sometimes we feel boring to write mysql insertion query to store data into database from a large form where are too many input fields (such as about 50 fields). We face problem to handle all the fields, sometimes we miss the field name. Here is a small trick to store data from such a large form.

In this trick, we have to do same naming of table fields and input fields. For example –

[html][/html]

Then the field name of the database will be “first_name”

Then the php code will be:

Suppose, name of the submit button is submit [html][/html]

[php]
safe_entry($_POST); // here obj is the object; safe_entry is a custom function which confirms the input validation of XSS and mysql injection; otherwise you can use $data = safe_entry($_POST); or simply use $data = $_POST;

$field = $value = array(); //two blank array in which field names and field values will be stored

foreach($data as $key=>$val)

if($key != ‘submit’)

{

array_push($field, $key);

array_push($value, $val);

}

$fields = implode(‘,’, $field);

$values = implode(“‘, ‘”, $value);

$sql = “insert into tablename($fields) values(‘$values’)”;

$query = $obj->insertQuery($sql); //use direct function mysql_query() in stead of custom function and object

?>
[/php]

That’s it! This code will store data from a large form. Thanks.

post

jSlider Plugin for jQuery (for 3 horizontal div)

This is my first jQuery plugin. Not so perfect, but it can be used I think :)

This plugin is very easy to use.

Doc:
This is a small slider content plugin for three horizontal floated div. By clicking on top menu, the divs switch.

1. Just pass the master div id which is wrapping the three floating div in the parameter field named master.
2. Pass id of the three floated divs’ in label parameter under jid index
3. Pass id of the three links’ in label parameter under links index

That’s It!
You don’t have to mention floated div in css.

Javascript Code:
[html]

$(document).ready(function(){
$.fn.jSlider({
//”width”:null,
//”height”:null,
“master”:”content”,
“labels”:[
{“jid”:”one_content”, “links”:”one”},
{“jid”:”two_content”, “links”:”two”},
{“jid”:”three_content”, “links”:”three”},
]
});
});

[/html]

HTML Code:
[html]

This is DIV 1

This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1.

This is DIV 2

This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2.

This is DIV 3

This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3.

[/html]

CSS Code:
[css]

#wrapper{
width:100%;
overflow:hidden;
color:#990000
}

#header{
width:100%;
height:30px;
background:#0033FF;
color:#FFFFFF;
}

#content{
overflow:hidden;
}

#header a{
padding:5px 15px;
color:#FFFFFF;
}

#one_content{
background:url(images/one.jpg) repeat;
}

#two_content{
background:url(images/two.jpg) repeat;
}

#three_content{
background:url(images/three.jpg) repeat;
}

[/css]

That’s it !

post

A Very Simple jQuery Drop Down Menu Plugin

This is a very simple jquery Drop Down Menu Plugin, vertically no doubt. Add latest jQuery in your html like:

[html]

[/html]

[if u don’t have jQuery in your server]

HTML Code:
[html]

[/html]
Just declare a class named “parent” in the li tag in which you have a submenu. Then its is done.

CSS Code:
[css]
div#menu ul li{
float:left;
}

div#menu ul li a{
display:block;
line-height:27px;
text-align:center;
color:#FFFFFF;
font-size:12px;
padding:0 13px;
border-right:1px solid #017302;
}

div#menu ul li a:hover, div#menu ul li a.active{
text-decoration:none;
}

.parent{
position:relative;
}

.parent ul{
position:absolute;
top:100%;
overflow:hidden;
left:0;
display:none;
background:#4CA82E;
}

div#menu ul li ul li a{
background:none;
width:auto !important;
white-space:nowrap;
text-align:left;
}

div#menu ul li ul li a:hover{
text-decoration:underline;
}

div#menu ul li ul li{
width:auto !important;
float:none;
}
[/css]

Now put the following code in your tag just below of the declaration of jQuery:
[html]

$(document).ready(function(){
$(“.parent”).hover(function(){
$(this).find(“ul”).show(“slow”);
}, function () {
$(this).find(“ul”).hide(“slow”);
});
});

[/html]
That’s it! Boom!! If you have this plugin just declare a class named “parent” in your

  • tag in which you have submenu.

    Thanks.

  • post

    Setup a web server in Linux Ubuntu

    Try the following code in terminal:

    That’s It! In the installation you may be asked for mysql password for root. Set as you wish but remember it as you will need it.

    Thanks: Ronju vai

    post

    Some Security Issue (php)

    Never, Ever, Trust Your Users

    It can never be said enough times, you should never, ever, ever trust your users to send you the data you expect. I have heard many people respond to that with something like “Oh, nobody malicious would be interested in my site”. Leaving aside that that could not be more wrong, it is not always a malicious user who can exploit a security hole – problems can just as easily arise because of a user unintentionally doing something wrong.

    So the cardinal rule of all web development, and I can’t stress it enough, is: Never, Ever, Trust Your Users. Assume every single piece of data your site collects from a user contains malicious code. Always. That includes data you think you have checked with client-side validation, for example using JavaScript. If you can manage that, you’ll be off to a good start. If PHP security is important to you, this single point is the most important to learn. Personally, I have a “PHP Security” sheet next to my desk with major points on, and this is in large bold text, right at the top.

    Global Variables

    In many languages you must explicitly create a variable in order to use it. In PHP, there is an option, “register_globals”, that you can set in php.ini that allows you to use global variables, ones you do not need to explicitly create.

    Consider the following code:
    [php]
    if ($password == “my_password”) {

    $authorized = 1;

    }

    if ($authorized == 1) {

    echo “Lots of important stuff.”;

    }
    [/php]

    To many that may look fine, and in fact this exact type of code is in use all over the web. However, if a server has “register_globals” set to on, then simply adding “?authorized=1″ to the URL will give anyone free access to exactly what you do not want everyone to see. This is one of the most common PHP security problems.

    Fortunately, this has a couple of possible simple solutions. The first, and perhaps the best, is to set “register_globals” to off. The second is to ensure that you only use variables that you have explicitly set yourself. In the above example, that would mean adding “$authorized = 0;” at the beginning of the script:

    [php]
    $authorized = 0;

    if ($password == “my_password”) {

    $authorized = 1;

    }

    if ($authorized == 1) {

    echo “Lots of important stuff.”;

    }
    [/php]

    Source: www.addedbytes.com/writing-secure-php/writing-secure-php-1/

    Comments are appriciated.

    post

    Face Ditector Jquery Plugin

    Face detection is a common feature in most digital cameras today; the white or red square that pops around someones face when we are focusing the camera on that person. Face detection algorithms enables the software to pinpoint the locations and sizes of human faces in digital images, whatever the surrounding objects may be.

    Face-Detection is a jQuery plugin that enables you to detect human faces in images. Besides the crucial algorithm that does the main work it uses HTML5 Canvas element to grab the image data. This means that the plugin only works on browsers that support the HTML5 Canvas element. A immediate application I thought of was to use it to automatically crop faces from pictures to be used as profile photos.

    I tried it on various types of images – groups of people, individuals, portraits – and it got a detection success of around 85%. As you can see from the demo given, it fails to detect the face on the extreme right. Still, quite nice for such a small piece of Javascript; with some more tweaks to the detection code by the author, the accuracy will get better over time and we can think of more browser applications of these concepts.

    Source:

    www.codediesel.com/javascript/face-detection-using-jquery/

    post

    header() function in the middle of a php page

    We can’t use header() function in the middle of a page in php. header() function is used for redirection. If the page prints something before this function then we get a message like “header already sent by….blablabla”.

    But we have another way to use header() function in anywhere of a page. We have to use two more function to make it working perfectly. Those two are: ob_start() in the first line of a page a and ob_flush() in the last line of that page We can omit the second one but there are some problem. I will discuss it later.

    So, the final syntax is:

    [php]

    [/php]

    This is one type of buffering. The server will buffer all the content and then print together. If there is any header() function then it works first. But of course keep it in mind that, this method will increase program run-time. So, enjoy.

    Any comments are appreciated…