Im using Contact Grabber API to retrieve address book contacts.

我使用Contact Grabber API来检索地址簿联系人。

My intention is to then allow the user to select their contacts (via checkbox list) and insert these values into a database.

我的目的是让用户选择他们的联系人(通过复选框列表)并将这些值插入数据库。

HTML for list:

列表的HTML:

<input type="checkbox" name="user_email" value="{users_email}" />

JQUERY to post data to PHP form

JQUERY将数据发布到PHP表单

    $("#divDone").click(function() {
        var data = { 'user_email' : []};
        $(":checked").each(function() {
          data['user_email'].push($(this).val());
        });
        $.post("ajax.php", data);
    });

ajax.php

ajax.php

var_export($_POST);

The ajax.php file echo's the following sample (of selecting two contacts)

ajax.php文件echo是以下示例(选择两个联系人)

array (
 'user_email' => 
  array (
    0 => 'gmail',
    1 => '{email1}',
    2 => '{email2}',
  ),
)

How do extract the email values and store them into my database? Is this method correct?

如何提取电子邮件值并将其存储到我的数据库中?这种方法是否正确?

Thank you all in advance

谢谢大家

George

乔治

1 个解决方案

#1


1

I hope you know what a MySQL database is and how to set up a table, see below for a basic example where you take all the emails and just put them in a table called Emails which has one column email

我希望你知道MySQL数据库是什么以及如何设置表,请参阅下面的一个基本示例,其中您将收集所有电子邮件,并将它们放在一个名为Emails的表中,该表有一列电子邮件

//Did we get a post?
if(empty($_POST['user_email']) && is_array($_POST['user_email'])) {
  echo "No Email's received. Check the post.";
} else {
  $emails = $_POST['user_email'];

  $errors = "";

  //## Connect to MYSQL here ##//
  $con = null; //SEE ABOVE

  //For all the posted emails
  foreach($emails as $email) {
    //Trim and escape the input
    $email = mysqli_real_escape_string(trim($email));
    $sql = "INSERT INTO Emails (email) ";
    $sql += "VALUES ('$email')";

    //If an error occurred add it to the list
    if (!mysql_query($sql,$con)) $errors += mysql_error()."\n";
  } //for each

  //Any errors?
  if(!empty($errors)) echo $errors;
}

更多相关文章

  1. 为什么jQuery的电子邮件验证regex如此简单?
  2. 使用pdf附件发送PHP电子邮件
  3. PHP将邮件发送到多个电子邮件地址
  4. 使用GMail SMTP服务器从PHP页面发送电子邮件
  5. 来自php表单的样式电子邮件
  6. 如何检查电子邮件id是否存在?
  7. Yii2之发送电子邮件
  8. 如何在php imap函数中看到看不见的电子邮件
  9. 如何从android的联系人姓名中获取联系人的号码?

随机推荐

  1. 异步执行多个任务并在JavaScript函数中返
  2. Java-控制台传递参数
  3. 怎样让自己对编程感兴趣?
  4. 数据结构-java与c实现带头结点的单链表
  5. 本地方法中printf如何传给java--java系统
  6. Maven:主线程中的NoClassDefFoundError
  7. spring boot返回date类型
  8. 跨站脚本专题(XSS)
  9. JavaScript三种弹出框(alert,confirm和prom
  10. 是否有缩放因子方法用于Android的多分辨