Wednesday, October 31, 2012

transaction in mysql php

<?php 
MYISAM Not Support Transaction 

/*
CREATE TABLE IF NOT EXISTS `table1` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(250) NOT NULL,
  `address` varchar(250) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
*/

$host 'localhost'
$user 'rajeev'
$password 'mypass';
$db 'demo'

$con mysql_connect($host$user$password);

mysql_select_db$db);

mysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");  

 
$query "INSERT INTO table1 (name,address) values ('name','bhopal')";
 
$result mysql_query($query);
  

if($result){
 
mysql_query("COMMIT");
 }  else {
 
mysql_query("ROLLBACK");
 }
 
 
mysql_close();

?>

Saturday, October 27, 2012

Create New User In Mysql with permission


create new user in mysql database
set user permissions mysql
delete user permissions in mysql



rajeev=User Name
mypass= Password
demo= database name

  // create user
CREATE USER 'rajeev'@'localhost' IDENTIFIED BY  'mypass' ;

   // set permission  in demo database 
GRANT SELECT, INSERT, DELETE ON  demo.* TO rajeev@'localhost' IDENTIFIED BY 'mypass';

 // set all permission in demo database
GRANT ALL ON demo.* to 'rajeev'@'localhost';

 // remove access permission from demo database
REVOKE select, UPDATE, DELETE ON demo.*  FROM 'rajeev'@'localhost';

 // remove all permission 
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'rajeev'@'localhost';

 // select user detail  from database 
select * from mysql.user where User='rajeev';


Friday, October 26, 2012

Email Validation In PHP

Email address Validation in PHP   

<form> Email Address: <input type='text' name='email'> <input type='submit' value='Submit'> </form>
 
<?php
 $email
=$_REQUEST['email']; 


 
$expression "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$"


 if (
eregi($expression$email)) {
 echo 
'Valid Email'


 } else { 


 echo 
'Invalid Email';
 }
 
?>

Tuesday, October 2, 2012

user already exits

This Code Is use for User name Already Exits or email id already exits 

here this function call using Ajax Method 

<?php 

function ckhuserid($udetail){

$arr=explode("!@@@!",$udetail); 

if(
$arr[1]=='edit'){

$val=executescalar("user","id","uname='".$arr[0]."' and id<>'".$arr[2]."' ""","false","str"); 

} else { 


$val=executescalar("user","id","uname='".$arr[0]."'""","false","str");
 }
if(
$val!=''){ // alresdy exist 
 
echo "yes";
}

?> 


// JavaScript Code

<script>
            
function ckhuserid(x,cas,id){ // x=this; cas= case=registration or edit profile , id=user id on edit time 
uname=$(x).val();
str=uname;
if(cas=='edit'){
str=uname+"!@@@!edit!@@@!"+id;
}
$.ajax({
  type: 'POST',
  url: "admin/Ajax/functions.php?f=ckhuserid&p="+str,
  data: {},
  success: function(data12){ 
 // alert(data12);
  if(data12=='yes'){
      alert("user name already exist"); $(x).focus(); return false ;
  }   
   
  }});
    return true ;
}
</script> 



// calling method 

<input type="text" onblur="return ckhuserid(this,0,0)"  /> // add time

<input type="text" onblur="return ckhuserid(this,'edit',id)"  /> // edit  time