请我需要有关如何将表单数据发布到也进入数据库的 url 的帮助。这是我开发的代码,但它似乎不起作用,它没有将信息发送到数据库和 curl
include_once('Libraries/libraries.php');
//send the info to this page via POST method.
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$address = $_POST['address'];
$state = $_POST['price_2'];
$v_merchant_id = $_POST['v_merchant_id'];
$merchant_ref = $_POST['merchant_ref'];
$memo = $_POST['memo'];
$item_1 = $_POST['item_1'];
$price_1 = $_POST['price_1'];
$item_2 = $_POST['item_2'];
$price_2 = $_POST['price_2'];
$notify_url =$_POST['notify_url'];
$success_url = $_POST['success_url'];
$fail_url = $_POST['fail_url'];
$total= $_POST['price_2'] + $_POST['price_1'];
if ($price_2 == 'Lagos'){
$item_2='COST OF DELIVERY WITHIN LAGOS';
$price_2='';}
elseif ($price_2 !='lagos'){
$item_2='COST OF DELIVERY OUTSIDE LAGOS';
$price_2='5000';};
//connect to database a run sql "INSERT INTO" query.
if (isset($_POST['name'])){
$sql = "INSERT INTO customers (name,phone,email,address,price_2,v_merchant_id,merchant_ref,memo,item_1,price_1,total)
VALUES (:name,:phone,:email,:address,:price_2,:v_merchant_id,:merchant_ref,:memo,:item_1,:price_1,:total)";
$q = $conn->prepare($sql);
$q->bindParam(':name', $name, PDO::PARAM_STR);
$q->bindParam(':phone', $phone, PDO::PARAM_STR);
$q->bindParam(':email', $email, PDO::PARAM_STR);
$q->bindParam(':address', $address, PDO::PARAM_STR);
$q->bindParam(':price_2', $price_2, PDO::PARAM_STR);
$q->bindParam(':v_merchant_id', $v_merchant_id, PDO::PARAM_STR);
$q->bindParam(':merchant_ref', $merchant_ref, PDO::PARAM_STR);
$q->bindParam(':memo', $memo, PDO::PARAM_STR);
$q->bindParam(':item_1', $item_1, PDO::PARAM_STR);
$q->bindParam(':price_1', $price_1, PDO::PARAM_STR);
$q->bindParam(':total', $total, PDO::PARAM_STR);
$q->execute();
};
$loc = 'location:https://voguepay.com/pay/?v_merchant_id='.$v_merchant_id.'&merchant_ref='.$merchant_ref.'&memo='.$memo.'&item_1='.$item_1.'&price_1='.$price_1.'&item_2='.$item_2.'&price_2='.$price_2.'¬ify_url='.$notify_url.'&success_url='.$success_url.'&fail_url='.$fail_url.'';
header($loc);
//that last line redirects the user to the api site submitting the username.
这是我的卷曲
//preparing the posted value as argument and value for the sms gateway
$postValue = "v_merchant_id=".$v_merchant_id."&merchant_ref=".$merchant_ref."&memo=".$memo."&item_1=".$item_1."&price_1=".$price_1."&item_2=".$item_2."&price_2=".$price_2."¬ify_url=".$notify_url."&success_url=".$success_url."&fail_url=".$fail_url."";
//the sms gateway address provided by your gateway
$apiUrl = "https://voguepay.com/pay/";
//next is to fake a browser form submitted
//firefox is our choosing browser
$browserType ="Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
//initiating the curl library
$ci = curl_init();
//set the url to be used for processing the data
curl_setopt($ci, CURLOPT_URL,$apiUrl);
curl_setopt($ci, CURLOPT_HEADER, true);
curl_setopt($ci, CURLOPT_FOLLOWLOCATION, false);
//set our browser type that has been initiad before
curl_setopt($ci, CURLOPT_USERAGENT, $browserType);
//set the maxmium time to execute the script before timing out
curl_setopt($ci,CURLOPT_CONNECTTIMEOUT,2);
//accept the response after the execution
curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
// set the post method for passing variables to the server
curl_setopt($ci, CURLOPT_POST, 1);
//assigning the values to be posted to the sms gateway
curl_setopt($ci, CURLOPT_POSTFIELDS, $postValue);
//execute the function and get result from the gateway
$a=curl_exec ($ci);
curl_close ($ci); // close the connection