存储过程和PHP表单

存储过程和PHP表单,php,mysql,html,stored-procedures,Php,Mysql,Html,Stored Procedures,希望我在这条路上走对了。我准备了一个存储过程,用于将客户详细信息添加到我的数据库中: 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

希望我在这条路上走对了。我准备了一个存储过程,用于将客户详细信息添加到我的数据库中:

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
现在,我想将此存储过程与html表单(类似于下面的表单)一起使用,将客户添加到我的客户表中

<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代码吗

add-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_变量


非常感谢。

我希望您知道如何将值从html页面发送到php代码


好的,试试这个

Hi@elrado,感谢您的回复。我收到以下错误:致命错误:对非对象调用成员函数prepare()。有什么想法吗?谢谢
$dbh=config.php()
应该是
require('config.php')。我猜你来自另一种语言,不知道你需要文件,你不能像函数一样调用它们。太好了,谢谢你,这就成功了!
<?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";
?>