2010-11-24 102 views
-1

下面的电子邮件查询应该由名为“ttemail”为0的字段触发。当我尝试使用它时,我得到You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1来自IF语句的MySQL错误

看来,电子邮件被发送出去的至少第一个用户名,其中TTEMAIL = 0

任何想法,为什么?

由于提前,

约翰

if($row["ttemail"] == 0){ 
    $mailaddress = $row['email']; 
    $link1 = "<a href='http://www...com/page.php'>Page Title</a>"; 
    $message1 = "Congratulations, message. 

       <br> 
       <br> 

       More Message 

       <br> 
       <br> 

       Please click the link below to see more. 
       <br> 
       <br> 

       $link1 
       ";  

    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $headers .= "From: Website Name <[email protected]>" . "\r\n"; 

    $queryem = mail($mailaddress, "Congratulations, message 
          $submission.", $message1, $headers); 

    //$ttquery = sprintf("Update login SET ".$row['ttemail']." = '1' WHERE username = ".$row['username']."");   

    mysql_query($queryem) or die(mysql_error()); 
    mysql_query($ttquery) or die(mysql_error()); 
} else { 
} 
+3

等等,什么?你使用`mail()`调用的返回值作为MySQL查询? – EboMike 2010-11-24 09:34:53

回答

0

我认为你缺少一个'在你的where子句。检查以下更正的查询 -

$ttquery = sprintf("Update login SET ".$row['ttemail']." = '1' WHERE username = '".$row['username']."'");