input type text clean data on mouse over in browser or finger click in mobile

Use mysql.ini to make secure in php

Here I am going to show how can we make our php mysql connection more secure and easy to edit while move in production usin .ini

1.Create a file named: my_setting.ini

write below content in this file start.

write below content in this file close.

now create a php file named: pdo.php
write below content in this file start.

write below content in this file close.

Now run your file pdo.php it will work properly.

There is no need to change any setting regarding this.

Try catch in php

Here we can see how try and catch works with simple example:

Output you can test here: http://sandbox.onlinephpfunctions.com/

Multiple database connection in php

index.php

<?php
$hostname =’localhost';
$username =’root';
$password =”;
$dbh1 = mysql_connect($hostname, $username, $password);
$dbh2 = mysql_connect($hostname, $username, $password, true);

mysql_select_db(‘database1′, $dbh1);
mysql_select_db(‘database2′, $dbh2);
$result1=mysql_query(‘select * from table1′, $dbh1);
$result2=mysql_query(‘select * from table1′, $dbh2);
while($row1=mysql_fetch_array($result1))
{
print_r($row1);
}
echo “<br>”;
while($row2=mysql_fetch_array($result2))
{
print_r($row2);
}
?>

 

database1.sql

— phpMyAdmin SQL Dump
— version 2.10.1
— http://www.phpmyadmin.net

— Host: localhost
— Generation Time: Jan 08, 2010 at 12:31 PM
— Server version: 5.0.45
— PHP Version: 5.2.5

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


— Database: database1

— ——————————————————–


— Table structure for table table1

CREATE TABLE table1 (
id int(2) NOT NULL auto_increment,
name varchar(255) NOT NULL,
PRIMARY KEY  (id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


— Dumping data for table table1

INSERT INTO table1 (id, name) VALUES
(1, ‘aa’),
(2, ‘bb’);
database2.sql

— phpMyAdmin SQL Dump
— version 2.10.1
— http://www.phpmyadmin.net

— Host: localhost
— Generation Time: Jan 08, 2010 at 12:31 PM
— Server version: 5.0.45
— PHP Version: 5.2.5

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


— Database: database2

— ——————————————————–


— Table structure for table table1

CREATE TABLE table1 (
id int(2) NOT NULL auto_increment,
name varchar(255) NOT NULL,
PRIMARY KEY  (id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


— Dumping data for table table1

INSERT INTO table1 (id, name) VALUES
(1, ‘aaqqqqqqqqqqqqqqqq’),
(2, ‘bbsssssssssssssssssssssssss’);

javascript validation on array check box

suppose your checkbox like this

 

<p style=”margin-left:20px;”>
<label><input type=”checkbox” name=”services[]” id=”services” value=”Copy Writing”/> Copy Writing</label>
<label><input type=”checkbox” name=”services[]” id=”services” value=”Brand Development”/> Brand Development</label>
<label><input type=”checkbox” name=”services[]” id=”services” value=”Press Advertising”/> Press Advertising</label>
<label style=”margin-left:40px;”><input type=”checkbox” name=”checkbox13″ id=”services”  value=”Photography”/> Photography </label>
<label style=”margin-left:8px;”><input type=”checkbox” name=”services[]” id=”services” value=”Others” /> Others</label>
</p>

 

and you want javascript validation of this array format checkbox

you can do by this way:

var chks = document.form1_feed.elements[‘services[]’];
var hasChecked = false;
//alert(chks.length);
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (!hasChecked){
alert(“Please select at least one.”);
chks[0].focus();
return false;
}

 

9844542127