2012-03-03 2 views
2

うまくいけば私はここに正しい道にいると思います。私は今、私の顧客テーブルに顧客を追加する(以下のような)HTMLフォームでこのストアドプロシージャを使用したいストアドプロシージャとPHPフォーム

DROP PROCEDURE `sp_add_customer`// 
CREATE DEFINER=`test`@`%` PROCEDURE `sp_add_customer`(IN in_name VARCHAR(100), in_address_line_1 VARCHAR(100), in_address_line_2 VARCHAR(100), in_address_line_3 VARCHAR(100), in_city VARCHAR(50), in_county VARCHAR(50), in_phone VARCHAR(30), in_mobile VARCHAR(30), in_email VARCHAR(100)) 
BEGIN 

    INSERT INTO customer(name, address_line_1, address_line_2, address_line_3, city, county, phone, mobile, email) 
    VALUES(in_name, in_address_line_1, in_address_line_2, in_address_line_3, in_city, in_county, in_phone, in_mobile, in_email); 

END 

:私は私のデータベースに顧客の詳細情報を追加するために準備ストアドプロシージャを持っています。

<form id="htmlForm" action="add-customer.php" method="post" class="form-horizontal"> 
    <input type="text" class="input-large" placeholder="Customer Name"><br/> 
    <input type="text" class="input-large" placeholder="Phone"><br/> 
    <input type="text" class="input-large" placeholder="Mobile"><br/> 
    <input type="text" class="input-large" placeholder="Email"><br/> 
    <input type="text" class="input-large" placeholder="Address Line 1"><br/> 
    <input type="text" class="input-large" placeholder="Address Line 2"><br/> 
    <input type="text" class="input-large" placeholder="Address Line 3"><br/> 
    <input type="text" class="input-large" placeholder="City"><br/> 
    <input type="text" class="input-large" placeholder="County"><br/> 
    <button type="submit" class="btn">Add Stock</button> 
</form> 

私は顧客フォームから顧客テーブルへの詳細をストアドプロシージャを使用して追加する必要があるPHPコードを教えてください。

アドオンcustomer.phpファイルが含まれています

<?php 

    //MySQL Database Connect 
    require once ("includes/config.php") 

    $name = $_POST['name']; 
    $phone = $_POST['phone']; 
    $mobile = $_POST['mobile']; 
    $email = $_POST['email']; 
    $address1 = $_POST['address1']; 
    $address2 = $_POST['address2']; 
    $address3 = $_POST['address3']; 
    $city = $_POST['city']; 
    $county = $_POST['county']; 

    try{ 
     $dbh=config.php(); 
     $stmt = $dbh->prepare('CALL sp_add_customer(:in_name, :in_address_line_1, :in_address_line_2, :in_address_line_3, :in_city, :in_county, :in_phone, :in_mobile, :in_email)'); 
     $stmt->bindParam(':in_name',$name,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_address_line_1',$address1,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_address_line_2',$address2,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_address_line_3',$address3,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_city',$city,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_county',$county,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_phone',$phone,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_mobile',$mobile,PDO::PARAM_STR,45); 
     $stmt->bindParam(':in_email',$email,PDO::PARAM_STR,45); 
     $stmt->execute(); 
    } 
    catch (PDOException $e) { 
    print "Error!: " . $e->getMessage() . "<br/>"; 
    die(); 
} 
?> 

私は次のエラー受けています現時点では: 解析エラー:構文エラー、予期しないT_VARIABLE

感謝を。

+1

は '$ DBH = config.phpの()' '( 'config.phpの')必要とされなければならないしてみてください;'。私の推測では、あなたは別の言語から来て、あなたがファイルを要求しなければならないことを知らず、それらを関数のように呼び出すことはできません。 – Xeoncross

+0

完璧なおかげで、そのトリックをやった! –

答えて

0

htmlページからPHPコードに値を送る方法を知っていれば幸いです。

php manual

<?php 
$stmt = $dbh->prepare("CALL sp_add_customer(?)"); 
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000); 

// call the stored procedure 
$stmt->execute(); 

print "procedure returned $return_value\n"; 
?> 

OKこの http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/

+0

こんにちは@elrado、ご回答いただきありがとうございます。次のエラーが表示されます。致命的なエラー:非オブジェクト上のメンバ関数prepare()を呼び出します。何か案は?ありがとう –