dongsui8162 2011-03-09 18:30
浏览 48

INSERT电子邮件地址,但忽略(如果存在||,如果后缀=现有后缀&&发件人名称=现有名称)MYSQL

I'm trying to insert a query into mysql using php, but to have restrictions.

$sql_insert = "
INSERT IGNORE 
    into `email` 
        (`message`,`useremail`,`senderemail`) 
    VALUES 
        ('$emailmessage','$email_address','$fromaddress') 
WHERE
";

$fromaddress is the value I want to make the constraints.

Here's an example

"Zazzle" <sender-1234@zazzle.com>

Don't insert if sender-1234@zazzle.com is in the senderemail field Don't insert if "Zazzle" is in the field and if @zazzle.com is also in the field.

  • 写回答

1条回答 默认 最新

  • dongxian7471 2011-03-09 19:19
    关注

    you can pull the email apart and then check the database to see if it exists in the database using preg_match. If using the example:

    --"Zazzle" <sender-1234@zazzle.com>
    

    $atIndex = strrpos($fromaddress, "@");
    $nameIndex = strrpos($fromaddress, "<");
    $domain = substr($fromaddress, $atIndex+1); # returns zazzle.com
    $local = substr($fromaddress, $nameIndex+1, $atIndex); # returns sender-123
    $name = substring($fromaddress, 0, $nameIndex-1); # returns "Zazzle"
    

    from there all you have to do is do a select/where query and if no results then to insert.

    $query = "SELECT * FROM email WHERE senderemail like '".$domain."'";
    $result=mysql_query($query);
    $num=mysql_num_rows($result);
    

    OR

    $query = "SELECT * FROM email";
    $result=mysql_query($query);
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         if(preg_match($domain, $row['senderemail'])) { $isPresent = true; }
    } 
    

    Preg match will look for the strings in the individual returned value and if present set a value to true. Then you can compare that value to be true/false and then to update your database.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度