我已从here下载了“订阅我们的简报”脚本。
该脚本包含一个表单和一个包含6个字段的mySQL数据库:id
,email
,name
,date_subscribe
,date_unsubscribe
和{{1} }。
表单非常简单:输入您的电子邮件,输入您的姓名并订阅。
我需要对此表单/数据库进行修改,以添加一个名为status
的额外字段。我编辑了mySQL数据库,并在promotion
之后将promotion
添加为varchar(250)。
我已修改PHP脚本以包含此新字段,但在提交表单时,新status
字段中的内容未添加到数据库中。
我已多次检查代码和表单,但我没有看到问题。
这是修改后的HTML格式(我的修改已标记):
promotion
这是填充数据库和修改的PHP:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Subscription form</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800' rel='stylesheet' type='text/css'>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<form id="subscribe-form" class="subscribe-form hide">
<div class="form-title">Subscribe to our newsletter</div>
<hr>
<div class="form-loading hide"><i class="fa fa-circle-o-notch fa-spin"></i></div>
<div class="form-message hide">
Thank you for subscribing!</div>
<div class="form-content">
<div class="group">
<label for="email">Your email</label>
<div class="input-prefix">
<i class="fa fa-user"></i>
<input id="email" name="email" class="form-control" type="email" placeholder="Your email">
</div>
</div>
<div class="group">
<label for="name">Your name</label>
<div class="input-prefix">
<i class="fa fa-envelope"></i>
<input id="name" name="name" class="form-control" type="text" placeholder="Your name">
</div>
</div>
I HAVE ADDED THIS SECTION
===========================
<div class="group">
<label for="promotion">PROMOTION NAME (Fill this with the promotion name)</label>
<div class="input-prefix">
<input id="promotion" name="promotion" class="form-control" type="text" placeholder="Promotion Name">
</div>
</div>
============================
<div class="group group-submit">
<label class="empty"></label>
<div align="right"><button class="btn-submit" type="submit">Subscribe</button></div>
</div>
</div>
<!--<div class="form-footer">
<a class="btn" data-toggle="unsubscribe" href="#">Unsubscribe</a>
</div>-->
<input type="hidden" name="action" value="subscribe">
</form>
<form id="unsubscribe-form" class="subscribe-form hide">
<div class="form-title unsubscribe">Unsubscribe from our newsletter</div>
<hr>
<div class="form-loading hide"><i class="fa fa-circle-o-notch fa-spin"></i></div>
<div class="form-message hide">
You've been unsubscribed.</div>
<div class="form-content">
<div class="group">
<label for="unsubscribe_email">Your email</label>
<div class="input-prefix">
<i class="fa fa-user"></i>
<input id="unsubscribe_email" name="unsubscribe_email" class="form-control" type="email" placeholder="Your email">
</div>
</div>
<div class="group">
<label class="empty"></label>
<div>
<input id="confirm" type="checkbox" name="confirm" value="T">
<label for="confirm">Click to confirm you want to unsubscribe</label>
</div>
</div>
<div class="group group-submit">
<label class="empty"></label>
<div align="right"><button class="btn-submit" type="submit">Unsubscribe</button></div>
</div>
</div>
<div class="form-footer">
<a class="btn" data-toggle="subscribe" href="#">Subscribe</a>
</div>
<input type="hidden" name="action" value="unsubscribe">
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
</body>
</html>
我错过了什么?
答案 0 :(得分:1)
你的php中有这样的东西吗?
if ($subscribe){
$fields = array(
array('name' => 'email', 'valid' => array('require', 'email')),
array('name' => 'name', 'valid' => array('require')),
array('name' => 'promotion', 'valid' => array()),
);
}
答案 1 :(得分:0)
在你的php中尝试改变这个
'promocao' => "'".$get['promocao']."'"
到这个
'promocao' => "'".$get['promotion']."'"
由于您的输入字段为name="promotion"
另请注意,在DB字段名称中promocao
如果没有,如果在您的数据库中,您的字段名称是促销,那么就像这样更改
'promotion' => "'".$get['promotion']."'"
答案 2 :(得分:0)
此处还添加promotion
字段:
if ($subscribe){
$fields = array(
array('name' => 'email', 'valid' => array('require', 'email')),
array('name' => 'name', 'valid' => array('require')),
);