ORM Sample in Mysql & PHP

//
/* -=-=- database functions -=-=- */
//

function InsertData($table,$columns){
    global $wpdb;

    $sql1 = "show fields from ".$table."";
    $result1 = mysql_query($sql1) or die($sql1);
    while($res = mysql_fetch_array($result1)){
    $cols[] = $res['Field'];
    }
    array_shift($cols);
   
    // create data //
        if(is_array($cols)){
            foreach($cols as $key => $value){
                $data .= "`".$value."`='".mysql_real_escape_string($columns[$value])."' , ";
            }
        }
    // create data //
   
    $qry = "insert into ".$table." set ".$data;
    $qry = eregi_replace(', $', '', $qry);
    $result = mysql_query($qry) or die($qry);
    return($result);
}

function updateData($table,$columns,$where){
    global $wpdb;
   
    $sql1 = "show fields from ".$table."";
    $result1 = mysql_query($sql1) or die($sql1);
    while($res = mysql_fetch_array($result1)){
    $cols[] = $res['Field'];
    }
    array_shift($cols);
   
    // create data //
        if(is_array($cols)){
            foreach($cols as $key => $value){
                if(is_array($columns) and array_key_exists($value, $columns)){
                    $data .= "`".$value."`='".mysql_real_escape_string($columns[$value])."' , ";
                }
            }
        }
    // create data //
   
    $qry = "update ".$table." set ".$data;
    $qry = eregi_replace(', $', '', $qry);
    $qry = $qry." ".$where."";
    $result = mysql_query($qry) or die($qry);
    return($result);
}

function deleteData($table,$where){
        global $wpdb;
        $qry = "delete from ".$table." ".$where."";
        $result = mysql_query($qry) or die($qry);
        return($result);
    }

//
/* -=-=- database functions -=-=- */
//

Modified cart functions v2

/** Cart Functions **/
function add($p_id,$name,$price,$qty,$image){

	if(!inCart($p_id)){
		$temp['id'] = $p_id;
		$temp['name'] = $name;
		$temp['price'] = $price;
		$temp['image'] = $image;
		$temp['qty'] = $qty;
		$temp['sub_tot'] = $price*$qty;

		$_SESSION['cart'][] = $temp;
		$_SESSION['total'] = $_SESSION['total']+$temp['sub_tot'];
		$_SESSION['tot_qty'] = $_SESSION['tot_qty']+$qty;
	} else {
		update($p_id,$_SESSION['cart'][$key]['qty']+$qty);
	}

}

function inCart($p_id){
	$temp = $_SESSION['cart'];
	if(is_array($temp) and !empty($temp)){
		foreach($temp as $key => $value){
			if($value['id'] == $p_id){
				return true;
			}
		}
	}
	return false;
}

function disp(){
	$temp = $_SESSION['cart'];
	if(is_array($_SESSION['cart'])){
	echo '<ul>';
 	foreach($temp as $key => $value){
		echo '<li>?Name '.$value['name'].' Price '.$value['price'].' x '.$value['qty'].' = '.$value['sub_tot'].'</li>';
	}
	echo '<li>Total = '.$_SESSION['total'].' Qty = '.$_SESSION['tot_qty'].'</li>'; 
	echo '</ul>';
	} else {
		echo 'Empty!';
	} 
}

}

PHP email validate

function check_email_address($email) {
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
return false;
}

$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++)
{
if(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]{0,63})|("[^(|")]{0,62}"))$",$local_array[$i]))
{
return false;
}
}

if (!ereg("^[?[0-9.]+]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2)
{
return false;
}
for ($i = 0; $i < sizeof($domain_array); $i++)
{
if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$",$domain_array[$i]))
{
return false;
}
}
}
return true;
}