【问题标题】:Newsletter preferences - add to database时事通讯偏好 - 添加到数据库
【发布时间】:2013-04-08 16:19:46
【问题描述】:

我想添加一个提交或保存按钮,将客户的答案添加到数据库表“时事通讯”。有人知道该怎么做吗?客户将已登录以获取其他详细信息以添加到表格中,我也许可以自己弄清楚。

<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>

【问题讨论】:

  • 你用的是mysql db吗?您是否在页面中连接了数据库并且只需要查询?
  • 在餐桌时事通讯中,您只存储客户的回答?
  • 我可以从 users 表中获取他们的姓名、电子邮件地址和 ID。我也想知道如何添加保存按钮,这样他们就不需要继续回答问题了。我对 html 不熟悉。

标签: html database forms post newsletter


【解决方案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">

【讨论】:

    猜你喜欢
    • 2015-06-24
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 2011-12-28
    • 2012-01-11
    相关资源
    最近更新 更多