dongzan0108 2015-10-18 16:12 采纳率: 0%
浏览 49
已采纳

显示mySQLi结果的PHP问题[关闭]

I'm having a rather confusing issue with a result that will not display. I'm creating a mailshot application and I'm trying to populate the email with the recipients name as well as an advert. The result works fine when I store it for use with the email that it sends to but it wont display inside the email body. Its a little hard to explain but here is the code that I am using. I have removed a lot of the email body as it was pretty large, where the ... are that is where I've take a load out.

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

<!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;">
            <?php
                echo "<div class=\"article\"><h2>Sending emails, please wait...</h2></div><br />";
                
                /*Variables for mail shot query*/
                $Keywords = $_SESSION['aKeywords'];
                $Lname = $_SESSION['aLname'];
                $Fname = $_SESSION['aFname']; 
                $CurrentJob = $_SESSION['aCurrentJob'];
                $DesiredJob = $_SESSION['aDesiredJob'];
                $CurrentSalary = $_SESSION['aCurrentSalary'];
                $DesiredSalary = $_SESSION['aDesiredSalary'];
                $Town = $_SESSION['aTown'];
                $Country = $_SESSION['aCountry'];
                $QualLevel = $_SESSION['aQualLevel'];
                $Languages = $_SESSION['aLanguages'];
                $TPC = $_SESSION['aTPC'];
                $TechnicalTerms = $_SESSION['aTechnicalTerms'];
                $ApplicantDivision = $_SESSION['aApplicantDivision'];
                
                $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 ?)";
            
                $KeywordsW = '%'.$Keywords.'%';
                $LnameW = '%'.$Lname.'%';
                $FnameW = '%'.$Fname.'%';
                $CurrentJobW = '%'.$CurrentJob.'%';
                $DesiredJobW = '%'.$DesiredJob.'%';
                $TownW = '%'.$Town.'%';
                $CountryW = '%'.$Country.'%';
                $QualLevelW = '%'.$QualLevel.'%';
                $LanguagesW = '%'.$Languages.'%';
                $TPCW = '%'.$TPC.'%';
                $TechnicalTermsW = '%'.$TechnicalTerms.'%';
                $ApplicantDivisionW = '%'.$ApplicantDivision.'%';
                
                $stmt = $con->prepare($query);
                $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);
    
                $stmt->execute() or die("Something went wrong, could not search :-(");
                $result = $stmt->get_result();
                $count = mysqli_num_rows($result);
                
                if ($count == 0) {
                    $output = 'Sorry, no results found!';
                    echo $output;   
                } 
                
                else {
                    while($row = $result->fetch_object()) {
                    $id = $row->Applicant_ID;
                    $queryResult = $con->query("SELECT Contact_Email FROM Client_Contacts WHERE Contact_ID = {$_SESSION['coID']}");
                    $ContactDetails = $queryResult->fetch_object();
                    $email = $ContactDetails->Contact_Email;
                    $firstname = $row->Applicant_First_Name;
                    $lastname = $row->Applicant_Last_Name;
                    
                    $mail_body = "<!doctype html>
<html>

...                           
                            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>";
                    $subject = $_SESSION['eSubject'];
                    $headers = "From:natalie@aztecksonline.net
Content-type: text/html
";
                    $to = $email;
                    
                    $mail_result = mail($to,$subject,$mail_body,$headers);
                    
                }
                }
                
                if($mail_result) {
                    echo "<script>window.alert(\"Mail Shot Sent!\");</script>";
                    
                    header('location: index.php');  
                } else {
                    echo "Something went wrong :-(";    
                }
            ?>
            
      </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>
          <script type="text/javascript">
            function googleTranslateElementInit() {
              new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
            }
          </script>
            </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
          
          if($cat_side_result = $con->query("SELECT Vacancy_ID, Vacancy_Job_Title, Vacancy_Location FROM Vacancies LIMIT 6")) {
                if($cat_side_result->num_rows) {
                    while($cat_side_row = $cat_side_result->fetch_object()) {
                        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>';
                        
                        mysqli_close($con);
                        }
                }
          }
           ?>

          </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="#">info@aztecksonline.net</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>

the $email populates fine as it sends the email with no issue but where it says in the email body $ContactDetails->Contact_First_Name, it does not display at all.

Have I done something rather dumb or is there something else wrong?

</div>
  • 写回答

3条回答 默认 最新

  • duanla3319 2015-10-18 16:24
    关注

    The query should look like this:

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

    You forgot to add Contact_First_Name and Contact_Last_Name into it so it wasn't even fetching them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)