2015-10-18 74 views
-1

我遇到了一個令人困惑的問題,導致無法顯示結果。我正在創建郵件應用程序,我試圖用收件人姓名以及廣告填充電子郵件。當我將它存儲爲與發送給它的電子郵件一起使用時,結果工作正常,但它不會顯示在電子郵件正文中。它有點難以解釋,但這裏是我正在使用的代碼。我已經刪除了很多電子郵件正文,因爲它非常大,在哪裏......這是我已經卸載的地方。顯示mySQLi結果的PHP問題

<?php require (__DIR__.'/connections/connections.php'); 
 
\t session_start(); 
 
\t if(isset($_SESSION["UserID"])){ 
 
\t }else{ 
 
\t \t header('Location: login.php'); 
 
\t } 
 
?> 
 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
<title>AzTecks Staff | Search Results</title> 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 
<link href="css/style.css" rel="stylesheet" type="text/css" /> 
 
<link rel="stylesheet" type="text/css" href="css/coin-slider.css" /> 
 
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> 
 
</head> 
 
<body> 
 
<div class="main"> 
 
    <div class="header"> 
 
    <div class="header_resize"> 
 
     <div class="menu_nav"> 
 
     <ul> 
 
      <li><a href="index.php"><span>Staff Home</span></a></li> 
 
      <li><a href="Register_Client.php"><span>Register Client</span></a></li> 
 
      <li class="active"><a href="Register_Applicant.php"><span>Register Applicant</span></a></li> 
 
      <li><a href="Add_vacancy.php"><span>Add Vacancy</span></a></li> 
 
      <li><a href="logout.php"><span>Logout</span></a></li> 
 
     </ul> 
 
     </div> 
 
     <div class="logo"> 
 
     <h1><a href="index.php"><span>AzTecks</span> <small style=" height: 12px; font-size: 11px;"> We Advise, We Avertise,</small><small style=" height: 12px; font-size: 11px;"> We Guarantee Not To Compromise</small></a></h1> 
 
     </div> 
 
     <div class="clr"></div> 
 
     <div class="slider"> 
 
     <div class="clr"></div> 
 
     </div> 
 
     <div class="clr"></div> 
 
    </div> 
 
    </div> 
 
    <div class="content"> 
 
    <div class="content_resize"> 
 
     <div class="mainbar" style="margin-top:0px;"> 
 
\t \t \t <?php 
 
\t \t \t \t echo "<div class=\"article\"><h2>Sending emails, please wait...</h2></div><br />"; 
 
\t \t \t \t 
 
\t \t \t \t /*Variables for mail shot query*/ 
 
\t \t \t \t $Keywords = $_SESSION['aKeywords']; 
 
\t \t \t \t $Lname = $_SESSION['aLname']; 
 
\t \t \t \t $Fname = $_SESSION['aFname']; 
 
\t \t \t \t $CurrentJob = $_SESSION['aCurrentJob']; 
 
\t \t \t \t $DesiredJob = $_SESSION['aDesiredJob']; 
 
\t \t \t \t $CurrentSalary = $_SESSION['aCurrentSalary']; 
 
\t \t \t \t $DesiredSalary = $_SESSION['aDesiredSalary']; 
 
\t \t \t \t $Town = $_SESSION['aTown']; 
 
\t \t \t \t $Country = $_SESSION['aCountry']; 
 
\t \t \t \t $QualLevel = $_SESSION['aQualLevel']; 
 
\t \t \t \t $Languages = $_SESSION['aLanguages']; 
 
\t \t \t \t $TPC = $_SESSION['aTPC']; 
 
\t \t \t \t $TechnicalTerms = $_SESSION['aTechnicalTerms']; 
 
\t \t \t \t $ApplicantDivision = $_SESSION['aApplicantDivision']; 
 
\t \t \t \t 
 
\t \t \t \t $query = "SELECT * FROM Applicants WHERE (? IS NULL OR CV_Text LIKE ?) AND (? IS NULL OR Applicant_Last_Name LIKE ?) AND (? IS NULL OR Applicant_First_Name LIKE ?) AND (? IS NULL OR Applicant_Current_Job_Title LIKE ?) AND (? IS NULL OR Applicant_Desired_Job_Title LIKE ?) AND (? IS NULL OR Applicant_Current_Salary >= ?) AND (? IS NULL OR Applicant_Desired_Salary >= ?) AND (? IS NULL OR Applicant_Town LIKE ?) AND (? IS NULL OR Applicant_Country LIKE ?) AND (? IS NULL OR Applicant_Qualification_Level LIKE ?) AND (? IS NULL OR Applicant_Languages LIKE ?) AND (? IS NULL OR T_P_C LIKE ?) AND (? IS NULL OR Applicant_Division LIKE ?) AND (? IS NULL OR Technical_Terms LIKE ?)"; 
 
\t \t \t 
 
\t \t \t \t $KeywordsW = '%'.$Keywords.'%'; 
 
\t \t \t \t $LnameW = '%'.$Lname.'%'; 
 
\t \t \t \t $FnameW = '%'.$Fname.'%'; 
 
\t \t \t \t $CurrentJobW = '%'.$CurrentJob.'%'; 
 
\t \t \t \t $DesiredJobW = '%'.$DesiredJob.'%'; 
 
\t \t \t \t $TownW = '%'.$Town.'%'; 
 
\t \t \t \t $CountryW = '%'.$Country.'%'; 
 
\t \t \t \t $QualLevelW = '%'.$QualLevel.'%'; 
 
\t \t \t \t $LanguagesW = '%'.$Languages.'%'; 
 
\t \t \t \t $TPCW = '%'.$TPC.'%'; 
 
\t \t \t \t $TechnicalTermsW = '%'.$TechnicalTerms.'%'; 
 
\t \t \t \t $ApplicantDivisionW = '%'.$ApplicantDivision.'%'; 
 
\t \t \t \t 
 
\t \t \t \t $stmt = $con->prepare($query); 
 
\t \t \t \t $stmt->bind_param("ssssssssssiiiissssssssssssss", $Keywords, $KeywordsW, $Lname, $LnameW, $Fname, $FnameW, $CurrentJob, $CurrentJobW, $DesiredJob, $DesiredJobW, $CurrentSalary, $CurrentSalary, $DesiredSalary, $DesiredSalary, $Town, $TownW, $Country, $CountryW, $QualLevel, $QualLevelW, $Languages, $LanguagesW, $TPC, $TPCW, $ApplicantDivision, $ApplicantDivisionW, $TechnicalTerms, $TechnicalTermsW); 
 
\t 
 
\t \t \t \t $stmt->execute() or die("Something went wrong, could not search :-("); 
 
\t \t \t \t $result = $stmt->get_result(); 
 
\t \t \t \t $count = mysqli_num_rows($result); 
 
\t \t \t \t 
 
\t \t \t \t if ($count == 0) { 
 
\t \t \t \t \t $output = 'Sorry, no results found!'; 
 
\t \t \t \t \t echo $output; \t 
 
\t \t \t \t } 
 
\t \t \t \t 
 
\t \t \t \t else { 
 
\t \t \t \t \t while($row = $result->fetch_object()) { 
 
\t \t \t \t \t $id = $row->Applicant_ID; 
 
\t \t \t \t \t $queryResult = $con->query("SELECT Contact_Email FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']}"); 
 
\t \t \t \t \t $ContactDetails = $queryResult->fetch_object(); 
 
\t \t \t \t \t $email = $ContactDetails->Contact_Email; 
 
\t \t \t \t \t $firstname = $row->Applicant_First_Name; 
 
\t \t \t \t \t $lastname = $row->Applicant_Last_Name; 
 
\t \t \t \t \t 
 
\t \t \t \t \t $mail_body = "<!doctype html> 
 
<html> 
 

 
...       
 
          \t Hello ".$ContactDetails->Contact_First_Name." ".$ContactDetails->Contact_Last_Name."<br /><br /><br /> 
 
          
 
          Below is a potential applicant for your consideration.<br /><br />".$row->Applicant_Advert."<br /><br /> 
 
          
 
          
 
...</html>"; 
 
\t \t \t \t \t $subject = $_SESSION['eSubject']; 
 
\t \t \t \t \t $headers = "From:[email protected]\r\nContent-type: text/html\r\n"; 
 
\t \t \t \t \t $to = $email; 
 
\t \t \t \t \t 
 
\t \t \t \t \t $mail_result = mail($to,$subject,$mail_body,$headers); 
 
\t \t \t \t \t 
 
\t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t \t 
 
\t \t \t \t if($mail_result) { 
 
\t \t \t \t \t echo "<script>window.alert(\"Mail Shot Sent!\");</script>"; 
 
\t \t \t \t \t 
 
\t \t \t \t \t header('location: index.php'); \t 
 
\t \t \t \t } else { 
 
\t \t \t \t \t echo "Something went wrong :-("; \t 
 
\t \t \t \t } 
 
\t \t \t ?> 
 
\t \t \t 
 
     </div> 
 
     
 
     <div class="sidebar"> 
 
     <div class="searchform"> 
 
      <form id="formsearch" name="formsearch" method="post" action="#"> 
 
      <span> 
 
      <input name="editbox_search" class="editbox_search" id="editbox_search" maxlength="80" value="Search Applicants" type="text" /> 
 
      </span> 
 
      <input name="button_search" src="images/search.gif" class="button_search" type="image" /> 
 
      </form> 
 
      <br /> 
 
      <div class="clr"><div id="google_translate_element"></div> 
 
\t \t <script type="text/javascript"> 
 
\t \t \t function googleTranslateElementInit() { 
 
\t \t \t new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element'); 
 
\t \t \t } 
 
\t \t </script> 
 
\t \t \t </div> 
 
     </div> 
 
     <div class="clr"></div> 
 
     <div class="gadget"> 
 
      <h2 class="star"><span>Sidebar</span> Menu</h2> 
 
      <div class="clr"></div> 
 
      <ul class="sb_menu"> 
 
      <li><a href="index.php">Staff Home</a></li> 
 
      <li><a href="Register_Client.php">Register Client</a><a href="#"></a></li> 
 
      <li><a href="Register_Applicant.php">Register Applicant</a></li> 
 
      <li><a href="Add_Vacancy.php">Add Vacancy</a></li> 
 
      <li><a href="logout.php">Logout</a></li></ul> 
 
     </div> 
 
     <div class="gadget"> 
 
      <h2 class="star"><span>Recent Vacancies</span></h2> 
 
      <div class="clr"></div> 
 
      <ul class="ex_menu"> 
 
      
 
      <?php 
 
\t \t 
 
\t \t if($cat_side_result = $con->query("SELECT Vacancy_ID, Vacancy_Job_Title, Vacancy_Location FROM Vacancies LIMIT 6")) { 
 
\t \t \t \t if($cat_side_result->num_rows) { 
 
\t \t \t \t \t while($cat_side_row = $cat_side_result->fetch_object()) { 
 
\t \t \t \t \t \t echo '<li><a href="View_Vacancy_Category.php?id='.$cat_side_row->Vacancy_ID.'">'.$cat_side_row->Vacancy_Job_Title.'</a><br /> In '.$cat_side_row->Vacancy_Location.'</li>'; 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t mysqli_close($con); 
 
\t \t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t } 
 
\t  ?> 
 

 
      </ul> 
 
     </div> 
 
     </div> 
 
     <div class="clr"></div> 
 
    </div> 
 
    </div> 
 
    <div class="fbg"> 
 
    <div class="fbg_resize"> 
 
     <div class="col c1"> 
 
     <h2>Clients Recently Joined</h2> 
 
     <a href="#"><img src="images/Small_Company_logo_ABP.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/Jumpahead1.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/Keopple_logo_small.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/Phantom_small.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/graves-capital_small.jpg" width="75" height="75" alt="" class="gal" /></a> <a href="#"><img src="images/global-financial-logo_small.gif" width="75" height="75" alt="" class="gal" /></a> </div> 
 
     <div class="col c2"> 
 
     <h2><span>Services</span> Overview</h2> 
 
     <p>At AzTecks we are committed to insuring you have total confidentiality, and do not share any data or information without your say so, please read our privacy agreement for more information.</p> 
 
     <ul class="fbg_ul"> 
 
      <li><a href="about.php">More about us</a></li> 
 
      <li><a href="Register-Coming_Soon.php">Privacy agreement</a></li> 
 
      <li><a href="contact.php">Contact us</a></li> 
 
     </ul> 
 
     </div> 
 
     <div class="col c3"> 
 
     <h2><span>Contact</span> Us</h2> 
 
     <p>If you have any querys about us or have any questions please feel free to contact us.</p> 
 
     <p class="contact_info"> <span>Address:</span>1 Shaw Street<br /> 
 
      Worcester , Worcestershire , UK<br /> 
 
      <span>Postcode:</span> WR1 3QQ<br /> 
 
     <span>Telephone:</span> 01905 700158<br /> 
 
      <span>E-mail:</span><a href="#">[email protected]</a></p> 
 
     </div> 
 
     <div class="clr"></div> 
 
    </div> 
 
    </div> 
 
    <div class="footer"> 
 
    <div class="footer_resize"> 
 
     <p class="lf">&copy; Copyright <a href="index.php">AzTecks</a>.</p> 
 
     <div style="clear:both;"></div> 
 
    </div> 
 
    </div> 
 
</div> 
 
</body> 
 
</html>

,因爲它發出的電子郵件沒有問題,但它在電子郵件正文$ContactDetails->Contact_First_Name說,它不會顯示在所有的$電子郵件填充的罰款。

我做了一些相當愚蠢的事情還是有其他問題?

+3

那麼我們是否真的需要閱讀所有這些代碼? –

回答

0

查詢應該是這樣的:

SELECT Contact_Email, Contact_First_Name, Contact_Last_Name FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']} 

你忘了添加Contact_First_NameContact_Last_Name到它,所以它甚至沒有獲取它們。

+0

哦,我的眩暈阿姨!這是盯着代碼很長的一個主要例子!你是在砸錢!真的很笨,現在哈哈。非常感謝你的幫助!我會投票給你,但我恐怕沒有足夠的代表:-( – willcaddy

+0

很高興我可以幫助一個編碼器。 – gommb

-1

首先在頂部添加。

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 

然後添加一個die();或退出();在實際執行任何數據庫更新之前,然後檢查php顯示的錯誤中的錯誤。

正常情況下,這是由於執行相關SQL的非法方式。試試看。

+1

這並不回答這個問題。它應該是一個評論。 –

+0

欣賞回覆,但user5200287正確。是我的一個愚蠢的錯誤¬_¬謝謝! – willcaddy

-2

首先,你應該寫一個可讀的代碼。

現在這是一個非常糟糕的意大利麪條代碼,帶有瘋狂的縮進(瞭解PSR)。

之後,將您的PHP與HTML分開,並將與數據庫的交互移至不同的圖層。

+0

這不是代碼審查,但你是對的 – gommb

+0

我知道,但如果有人的錯誤在一個像OPs這樣的代碼中,重構是唯一正確的方法, –

+0

這並不回答這個問題,它應該是一個註釋 –