所以我正在开发一个php web应用程序。这是我正在处理的表格(trackit.php)。
<?php
function curlPOST($fields) {
$url = 'http://example.com/mailit4.php';
//url-ify the data for the POST^M
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
$lid = $_GET["lid"];
$list_id = $_GET["list_id"];
$phone=$_GET["phone"];
/*
$filename = 'leadids.txt';
$contents = file($filename);
$myfile = fopen("leadids.txt", "a") or die("Unable to open file!");
*/
$fields = array('lid' => $lid, 'list_id' => $list_id, 'phone'=> $phone);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Client Appreciation Weekend 2016</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<table width="986" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/example" alt="example.com" width="600" height="133" style="margin-left:180px;" border="0" usemap="#Map" /></td>
</tr>
</table>
<table width="986" border="0" align="center" cellpadding="0" cellspacing="0">
<form action="<?curlPOST($fields)?>" method="post" >
<tr>
<td>
<label>Phonenumber:</label>
</td>
<input type="hidden" name="lid" id="lid" size="40" value= "<?=$lid?>">
<input type="hidden" name="list_id" id="list_id" size="40" value= "<?=$list_id?>">
<td >
<input type="text" name="phonenumber" id="phonenumber" size="40" value= "<?=$phone?>"> <br>
</td>
</tr>
<tr align="center">
<td>
<input type="submit" name="btnSubmit" value="Submit Data">
</td>
</tr>
</form>
</table>
</body>
</html>
?>
我使用curl post将这三个值发布到mailit4.php。当我单击提交时,它调用该函数并运行另一台服务器上的mailit4.php脚本。一切正常,但是当我试图将我的页面重定向到这个服务器上的thanks.html(trackit.php所在的位置)。它无所事事。任何人都可以请我如何重定向到thanks.html
这是我的mailit4.php代码
<?php
$db = mysqli_connect('localhost', 'example', 'example', 'example');
$lid = $_POST['lid'];
$list_id = $_POST['list_id'];
$phone=$_POST['phone'];
$sql = "SELECT list_id FROM exampleWHERE lead_id=$lid";
$result = mysqli_query($db,$sql);
$value = mysqli_fetch_row($result);
if ($value[0] != $list_id){
$body = "Leadid " . $lid . " : " . $list_id . "\n\n";
$subject = "Zombie Drip:" . $lid . " : " . $list_id;
mail("example@gmail.com", $subject, $body);
}
$query = mysqli_query($db, "UPDATE example SET list_id=$list_id,called_since_last_reset='N',phone_number=$phone WHERE lead_id=$lid");
if($query){
header('Location: http://example.com/thanks.html/');
exit;
}
else{
$body = "Leadid " . $lid . " : " . $list_id . "\n\n";
$subject = "It could not update the example due to some reasons " .$query ;
mail("example@gmail.com", $subject, $body);
}
&GT;
谢谢
答案 0 :(得分:1)
由于<form action="<?curlPOST($fields)?>" method="post" >
错误,此代码无法正常运行。
您没有回复curlPOST($fields)
所以当您加载此页面时,您的mailit4.php
正在加载一次,此表单的操作设置为自我<form action="" method="post" >
并且您是认为您的代码在每次提交时都正常工作会调用此页面以及mailit4.php
。您的正确操作将为<form action="" method="post" >
并在调用函数curlPOST
后放置此代码
if(!empty($ _ POST))curlPOST($ fields);
代码中的另一个问题是,
$lid = $_GET["lid"];
$list_id = $_GET["list_id"];
$phone=$_GET["phone"];
表单的方法为post
,您试图通过get
mailit4.php
中的意味着你正在向某个地方发送数据,这意味着数据已经刷新,然后你正在调用标题。 instate使用file_get_contents()
获取thanks.html
的内容,因为此脚本不会向浏览器发送任何内容。
答案 1 :(得分:0)
请从您的mailit4.php返回一些内容,如
If(mail($subject....))
{
echo "ok";
}
并在你的卷曲功能
If( $result == "ok" )
{
// redirect to thank you page
}
由于我正在使用手机输入
,因此我的想法很少希望它能帮到你
由于