2012-04-20 57 views
0

我有一個電子郵件正在生成併發送到一個文件中,該電子郵件中的鏈接鏈接到我的確認頁,然後應根據他們的選擇移動用戶名取得了。問題是,即使當我僅使用簡單的打印語句而沒有其他任何東西時,我也從確認頁面中得不到任何東西。我一直試圖弄清楚,但無濟於事,錯誤報告也是空白。這裏的兩個文件:PHP電子郵件與確認鏈接發送但確認鏈接不起作用

email.php(這充分作品)

<?php 

$link= mysql_connect(...............); //Establish connection to the MySQL server 

if (!$link) { 
die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db(.....); 

$confirm = md5(uniqid(rand())); 
$position = $_POST['position']; 
$team_name = $_POST['team_name']; 
$zip_code = $_POST['zip_code']; 
$userId = $_POST['userId']; 

$s=mysql_query("SELECT Coach, TeamId FROM TEAM WHERE TEAM.Name = '$team_name' AND TEAM.Zip  ='$zip_code'") OR die ("Error 1"); //Get result from query 

while($row=mysql_fetch_assoc($s)) 
{ 
$coachId = $row['Coach']; 
$teamId = $row['TeamId']; 
} 

$l=mysql_query("SELECT Name, Email FROM USER WHERE USER.UserId = '$userId'") OR die ("Error 3");  //Get result from query 

while($row = mysql_fetch_assoc($l)) 
{ 
$user_name = $row['Name']; 
$user_email = $row['Email']; 
} 

$q=mysql_query("SELECT Name, Email FROM USER WHERE USER.UserId = '$coachId'") OR die ("Error 4"); //Get result from query 

while($coach=mysql_fetch_assoc($q)) 
{ 
$to = $coach['Email']; 
$name = $user_name; 
$subject = "Scoutlet $position Request for The $team_name"; 

if($position == "Head Coach") 
{ 
    $message = "$name has requested to become the Head Coach for the $team_name."; 
    $message .= "\n\nClick on the following link to give $name permission to be the Head Coach of the $team_name (Located in the ZIP code $zip_code).\n\n"; 
    $message .="<a href=\"http://web.***.***/~***/confirmation.php?key=$confirm\">Click Here to make $name the Head Coach</a>"; 
} 
else 
{ 
    $message = "$name has requested to become a Score Keeper for the $team_name."; 
    $message .= "\n\nClick on the following link to give $name permission to be a Score Keeper for the $team_name (Located in the ZIP code $zip_code).\n\n"; 
    $message.="http://web.***.***/~***/confirmation.php?key=$confirm"; // way to prevent no spam, dont use txt 

} 

$headers = "From: ***"; 
$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$sent = mail($to, $subject, $message, $headers) ; 

if($sent) 
{ 
    print "sent"; 
} 
else 
{ 
    print "fail"; 
} 
} 
$sql=mysql_query("INSERT INTO CONFIRMATION(ConfirmationNumber, UserId, Email, TeamId, TeamName, Position)VALUES('$confirm', '$userId','$user_email','$teamId', '$team_name', '$position')") OR die ("Error 2"); //Get result from query 

mysql_close(); 
?> 

confirmation.php

<? 
    ini_set('display_errors',1); 
error_reporting(E_ALL); 
$confirm = $_GET['key']; 

$link= mysql_connect(***********); //Establish connection to the MySQL server 

if (!$link) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 
echo "connect4e"; 

mysql_select_db(**********); 

$sql1=mysql_query("SELECT * FROM CONFIRMATION WHERE ConfirmationNumber ='$confirm'") OR die ("Fail 1"); 

    while($row=mysql_fetch_assoc($sql1)) 
    { 
     $userId= $row['UserId']; 
     $user_email = $row['Email']; 
     $teamId = $row['TeamId']; 
     $team_name = $row['TeamName']; 
     $position= $row['Position']; 
    } 

    $sql2= mysql_query("INSERT INTO USER (Role) VALUES ('$position') WHERE UserId ='$userId'") OR die ("Fail 2"); 

    if($position =="Head Coach") 
    { 
     $sql3= mysql_query("INSERT INTO TEAM (Coach) VALUES ('$userId') WHERE TeamId ='$teamId'") OR die ("Fail 3a"); 
    } 
    else 
    { // do a check earlier on to see if the user is already a score keeper for that team 
     $sql3= mysql_query("INSERT INTO SCOREKEEPS_FOR (ScoreKeeper, Team) VALUES ('$userId', '$teamId')") OR die ("Fail 3b"); 
    } 

    $to= $user_email;   
    $subject="Welcome to Our Site"; 
    $headers = "From: ******"; 
    $message="Congratulations, you have been confirmed as a $position for The $team_name."; 

    $sent = mail($to,$subject,$message,$header); 
    if(sent) 
    { 
     $sql4=mysql_query("DELETE FROM CONFIRMATION WHERE ConfirmationNumber = '$confirm'") OR die ("Fail 5"); 
    } 
    else 
    { 
     print "fail"; 
    } 

?> 

我已經殺死了大量的時間只是試圖錯誤檢查哪些是一種浪費,所以希望更多的眼睛能夠幫助更快地解決問題。任何幫助或建議都會很棒。在此先感謝

+0

您是否嘗試過在您的確認文件中傾銷$ sql1以查看您的語句是否從數據庫獲取任何回覆? – Rooster 2012-04-20 14:37:19

+0

@JohnB是的,我做了,無論如何都是空白。就在一分鐘前,有人發佈了,然後刪除了短標籤<?在證實的開始是問題,我改變後,我的錯誤報告開始工作,所以我認爲我會從這裏很好,我不相信這是愚蠢的,雖然。感謝您的快速響應! – user1070764 2012-04-20 14:39:33

回答

1

可能是您的服務器僅與開始標記

<?php 

代替

<? 

http://us2.php.net/manual/en/language.basic-syntax.phptags.php

PHP還允許短標籤執行PHP(這是不鼓勵,因爲它們只有在使用short_open_tag ph啓用時纔可用p.ini配置文件指令,或者如果PHP配置了--enable-short-tags選項。

+0

沒有關係,我檢查了 – squarephoenix 2012-04-20 14:40:13

+1

不知道爲什麼我得到-1因爲你的PHP不工作,直到你更正了PHP開始標記 – 2012-04-20 14:41:36

+0

「你的PHP不是一直工作,直到你糾正了PHP的開始標記「他在哪裏說的?雖然我拿走了-1因爲你確實有很好的參考和良好的點 – squarephoenix 2012-04-20 14:44:30

-1

在您的confirmation.php中,您正在使用短打開標籤<? ... ?>。確保你的PHP短打開標籤是啓用或簡單地使用<?php ... ?>