新闻稿首选项 - 添加到数据库

时间:2013-04-16 09:58:17

标签: html database forms post newsletter

我想添加一个提交或保存按钮,将客户答案添加到数据库表'newsletter'中。任何人都知道如何解决这个问题?客户将已经登录以获取其他详细信息以添加到表格中,我可以自己弄清楚。

<div id="newsletter-settings">
                                <h3 style="margin-left:0; padding:0; font-size:14px; background:none; margin:0;">Your Newsletter Settings</h3>
                                <p>You can edit your newsletter preferences by checking the boxes below to suit your requirements.</p>

                                <form method="post">
                                    <label for="recieve-newsletter">Do you wish to receive the Make A Will Now email newsletter?</label>
                                    <input type="radio" name="recieve-newsletter" value="Yes" /><span>Yes</span>
                                    <input type="radio" name="recieve-newsletter" value="No" style="margin-left:20px;" /><span>No, not at the moment</span>

                                    <label for="newsletter-partners" style="margin-top:20px;">Do you wish to receive emails from carefully selected partners?</label>
                                    <input type="radio" name="newsletter-partners" value="Yes" /><span>Yes</span>
                                    <input type="radio" name="newsletter-partners" value="No" style="margin-left:20px;" /><span>No, not at the moment</span>
                                </form>
                            </div>

1 个答案:

答案 0 :(得分:1)

您可以使用jquery获取已选中按钮的值:

var val = $('input:radio[name=recieve-newsletter]:checked').val();

然后你可以对你的提交按钮说,用这样的函数在你的数据库中插入答案:

function insert(){ mysql_query("insert into newsletter (answer) values ('$val')");}

现在按钮就像那样

<input type="submit" OnClick="insert();" value="submit your answer">