2010年2月17日水曜日

//チェックしてます。
require_once("CheckUtil.class.php");
require_once("MySmarty.class.php");
require_once("Customer.class.php");
$aryPro=array();
$objCst=new Customer();
$objCst->setName($_POST['nam']);
$objCst->setZip($_POST['zip']);
$objCst->setAddress($_POST['address']);
$objCst->setTel($_POST['tel']);
$objChk=new CheckUtil();
$objChk->requiredCheck($objCst->getName(),"名前");
$objChk->lengthCheck($objCst->getName(),15,"名前");
$objChk->requiredCheck($objCst->getZip(),"郵便番号");
$objChk->regExCheck($objCst->getZip(),"^[0-9]{3}-[0-9]{4}$","郵便番号");
$objChk->requiredCheck($objCst->getAddress(),"住所");
$objChk->lengthCheck($objCst->getAddress(),50,"住所");
$objChk->requiredCheck($objCst->getTel(),"TEL");
$objChk->HanCheck($objCst->getTel(),"TEL");
$objChk->lengthCheck($objCst->getTel(),15,"TEL");
//showResult();で問題がなければメッセージが表示されない
$objChk->showResult();
$MySQLi = mysqli_init( );
$MySQLi->options( MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0" );
$db=new mysqli("localhost","dbpal","password","dbpal");
$db->query("BEGIN");
$intRst=$objCst->writeCustomer($db);
if($intRst===FALSE){
    $db->query("ROLLBACK");
} else {
    //MySQL4.1への対応
    $db->query("SET NAMES UJIS");
    $stt=$db->prepare("INSERT INTO ec_master(code,num,person) VALUES(?,?,?)");
    $stt->bind_param("sss",$code,$num,$person);
    for($i=0;$i<$_POST['cnt'];$i++){
        $code=$_POST['code'.$i];
        $num=$_POST['num'.$i];
        $person=$intRst;
        $flag=$stt->execute();
        if($flag===FALSE){
            $db->query("ROLLBACK");
            break;
        }
    }
    $db->query("COMMIT");
}
session_start();
session_destroy();
$o_smarty=new MySmarty();
$o_smarty->display("thanks.tpl");
?>

0 件のコメント:

コメントを投稿