我是编程新手,并制作了一个HTML表单,从客户那里收集数据,然后将其保存在数据库中(这是有效的)我唯一关注的两个部分是确认页面应该显示一个页面谢谢你的消息,但现在它直接进入主页。
其次有一个Facebook跟踪器编码似乎没有执行我不知道为什么。
请有人帮助我吗?
索引页面的编码:
<!DOCTYPE html>
<html>
<head>
<title>University of Salford -</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale = 1.0,user-scalable=no, maximum-scale=1.0" />
<link href="css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<!-- Add HTML 5 vaildation for older browser -->
<script src="js/forms/modernizr-custom.js" type="text/javascript"></script>
<script src="js/forms/polyfiller.js" type="text/javascript"></script>
<script src="js/forms/validation.js" type="text/javascript"></script>
</head>
<body>
<div id="headerImg"><img alt="header" src="images/salfordlogo.png"/></div>
<div id="intro">Welcome to the University of Salford</div>
<div class="para">
<ul>
<li>We welcome over 3000 international students per year from over 100 countries.</li>
<li>Our presence at MediaCityUK offers invaluable employability enhancing experience to our students across all disciplines.</li>
<li>To find out what we can offer you, why not come along to meet us in your country over the coming months.</li>
<li>Please fill in your details below to get more information about our courses and generous scholarship scheme.</li>
</ul>
</div>
<form action="process.php" name="form" id="form" >
<input type="text" name="firstName" id="firstName" placeholder="First Name" required="required"/>
<input type="text" name="surname" id="surname" placeholder="Family Name" required="required"/>
<input type="text" name="dob" id="dob" placeholder="DOB (01/01/88)" required="required"/>
<select name="nationality">
<option value="">Nationality</option>
<option value="Emirati">Emirati</option>
<option value="Ghanaian">Ghanaian</option>
<option value="Indian">Indian</option>
<option value="Iranian">Iranian</option>
<option value="Malaysian">Malaysian</option>
<option value="Nigerian">Nigerian</option>
<option value="Omani">Omani</option>
<option value="Pakistani">Pakistani</option>
<option value="Saudi">Saudi</option>
<option value="Sri Lankan">Sri Lankan</option>
</select>
<input type="email" name="email" id="email" placeholder="E-Mail" required="required"/>
<select name="areaCode" id="areaCode">
<option value="">Area Code</option>
<!--<option value="0044">+44 (UK)</option>-->
<option value="00233">+233 (GH)</option>
<option value="0091">+91 (IN)</option>
<option value="0098">+98 (IR)</option>
<option value="0060">+60 (MY)</option>
<option value="00234">+234 (NG)</option>
<option value="00968">+968 (OM)</option>
<option value="0092">+92 (PK)</option>
<option value="00966">+966 (SA)</option>
<option value="0094">+94 (LK)</option>
<option value="00971">+971 (AE)</option>
</select>
<input type="tel" id="mobile" name="mobile" placeholder="Mobile Number" required="required"/>
<input type="submit" value="Submit"/>
</form>
<div id="footer"><img alt="header" src="images/salfordheader.png"/></div>
</body>
</html>
进程页面的编码
<?php
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
//Start SMS API
//STEP 1: Configure SMS text and then input bitly link for confirm.php
require_once '../admin/lib/SmsApi/SmsApi.php';
$sendSms = new SmsApi();
$config = parse_ini_file("config/config.ini");
$body="Free Msg: \nHi [NAME], thank you for your interest in Salford. Click the link for more details http://bit.ly/salfordman ";
//End SMS API
//Connect to the mysql Db $con =
//mysql_connect($config['host'], $config['username'], $config['password']);
try{
$con = new PDO('mysql:host='.$config['host'].";dbname=".$config['database'].";charset=utf8",$config['username'],$config['password']);
} catch (PDOException $e){
header("Location: confirm.php?success=false");
exit;
}
$con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
//Select table to insert incoming data to. The tabel name is define in
//config.ini table = "{table}" mysql_select_db($config['database'],$con);
//check if the any of the get Value have data otherwise show error
foreach ($_GET as $value) {
if($value==""){
header("Location: confirm.php?success=false");
exit;
};
}
//STEP 2: Perform Find/Replace or add in corresponding fields
//User data fields from form in index file
$firstName =$_GET['firstName'];
$surname =$_GET['surname'];
$dob =$_GET['dob'];
$nationality =$_GET['nationality'];
$email =$_GET['email'];
$areaCode = $_GET['areaCode'];
$mobile =$_GET['mobile'];
//NEW MAIL VALIDATION NO NEED TO TOUCH!!!!!!!
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: confirm.php?success=false");
exit;
}
//build Mysql query
$preparedQuery = $con->prepare("INSERT INTO salford (firstName,surname,dob,nationality,email,areaCode,mobile)
VALUES (:firstName,:surname,:dob,:nationality,:email,:areaCode,:mobile)");
$result = $preparedQuery->execute(array(
':firstName' => $firstName,
':surname' => $surname,
':dob' => $dob,
'nationality' => $nationality,
':email' => $email,
'areaCode' => $areaCode,
'mobile' => $mobile
));
$con = null;
if (!$result){
//error page
header("Location: confirm.php?success=false&type=2");
exit;
}else{
header("Location: http://educate.netmuk.com/salford/minisite");
//Replace placeholder with dynamic text;
$body = str_replace("[NAME]", $fullname, $body);
//Check if leading 0 is present, for the area code
if(preg_match("/^0/",$mobile)){
$msisdn = preg_replace("/^0/", $areacode, $mobile);
}else{
$msisdn =$areacode.$mobile;
}
//build api sms query
//below block commented by steve. switched to use iGate class
/*$urlQuery = "?body=".urlencode($body)."&msisdn=".$msisdn."&oadc=cccu";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $config['smsApi'].$urlQuery,
CURLOPT_RETURNTRANSFER=> TRUE
));
curl_exec($ch);
curl_close($ch);*/
$sendSms->addMessage(
array('msisdn'=> $msisdn,
//Add content here
' message'=> $body
));
//Set Sender Here
$sendSms->setSender('Salford')->send();
//$iGateService->sendSMS returns TRUE on success, but we do nothing with it here
}
?>
编码具有Facebook跟踪器的确认页面以及感谢信息
<!DOCTYPE html>
<html>
<head>
<title>Salford</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale = 1.0,user-scalable=no, maximum-scale=1.0" />
<link href="css/style.css" rel="stylesheet"/>
</head>
<body>
<div id="headerImg"><img alt="header" src="images/salfordlogo.png"/></div>
<?php if($_GET['success']=="true"):?>
<div id="intro">Submitted!</div>
<div>
Thank you, we will be in touch shortly
</div>
<?php else:?>
<div>
There was an error, Please try again in a few moments.
</div>
<?php endif;?>
<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = '6018025148480';
fb_param.value = '0.00';
fb_param.currency = 'GBP';
(function(){
var fpw = document.createElement('script');
fpw.async = true;
fpw.src = '//connect.facebook.net/en_US/fp.js';
var ref = document.getElementsByTagName('script')[0];
ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=6018025148480&value=0&currency=GBP" /></noscript>
</body>
</html>
答案 0 :(得分:2)
在处理完所有代码后,您没有链接重定向的位置(在进程页面的编码中),如果出现错误,您只有重定向。所以,如果一切正常,在文件的末尾,应该有一个像这样的重定向代码:
header("Location: confirm.php?success=true");
因此,请在游行页面中?>
之前准确添加此代码!