Jump to content

PHP Help needed


tazz24mania

Recommended Posts

Hello, I recently had a website crash. After restoring it i have a page that refuses to show any information from the database. 

 

When a user logs in they goto a page called 'My Events'. This then should list all the events that the user has paid for. Upon clicking a linkto a particular event it reloads the page with extra GET tags to get details of that event. 

 

Now the problem is the first step when a user first goes to the page. It refuses to show any events that the user is signed up for. Please help.

 

Code Below.

<?php
session_start();
$page_title = 'My Events';
$username = $_SESSION['cre_email'];
if (!isset($_SESSION['loggedin']))
{
echo "<script language=\"JavaScript\">window.location='buy.php?id=$id'</script>";
}

include("includes/headerOut.php");
include("db/pddb.php");
include("email.php");?>
 <!--main Nav-->
      <?php include('includes/mainNav.php'); ?>
    <!--Section Title-->
    <h1><?php echo $page_title; ?></h1>
 <!--primary Content-->
    <div id="primaryContent">
     <?php include('includes/login.php'); ?>
    </div>
    <!--Main Content-->
    <div id="mainContent">
    <?php
echo("<div style='min-height:400px;'><span style='font-size:11px;'>");
$username = $_SESSION['cre_email'];
$cust_id = $_SESSION['cust_id'];
$email = $_POST['email'];
$eve_id = $_GET["id"];
$daysActive = 7; //Change this to number of days an matching on an event is active for.

if ($_SESSION['loggedin'] == 1)
{ 
    $q_events = "SELECT *, date_format(eve_date, '%D %b %Y – %W') as FormatedDate, datediff(now(), eve_date) as PastFuture FROM pd_events AS e 
                INNER JOIN pd_booking AS p ON e.eve_id = p.eve_id 
                INNER JOIN pd_credentials AS c ON c.cre_cust_id = p.cust_id WHERE c.cre_email='$username'
                ORDER BY eve_date DESC";

    $r_events = mysql_query($q_events);
    echo mysql_error();
      echo("<script>
      function enableSubmit()
      {
      document.form1.submit.disabled = false;
      }
      
      function disableSubmit()
      {
      document.form1.submit.disabled = true;
      }      
      </script>");
  if($_GET["id"]=="")
  {

    echo("<h2><span class=\"RedGbColor\">My Events</h2>");
    //this is a list of all events this member has registered for
  

    while ($row = mysql_fetch_array($r_events)) 
    { 
      $_SESSION['cust_id'] = $row[cust_id];
      if($row["PastFuture"]>3)
      {
        $eve_status = "<a href='event_matches.php?id=$row[eve_id]'>View My Matches</a>";
      }
      else
      {
        if($row["PastFuture"]>0)
        {
          $eve_status = "<a href='event_matches.php?id=$row[eve_id]'>View Potential Matches</a>";
        }
        else
        {
           $eve_status = "<span style='color:#C30E42'>Upcoming Event</span>";
        }
      }

      echo("<br />
      <p><b>Event Venue: </b> $row[eve_ven_location], $row[eve_ven_name]<br/>
      <b>Type: </b> $row[eve_type_name]<br/>
      <b>Date & Time:</b> $row[FormatedDate], $row[eve_time]<br/>
      <b>Status:</b> $eve_status<br/><br/></p>
      
      ");
    }
  }
  else
  {
    
    $i = 0;
    while ($row = mysql_fetch_array($r_events)) 
    {
      if($row["eve_id"]==$eve_id)
      {
        $i = $row["PastFuture"];
      }
    }
    
    

    
    if($i>$daysActive)
    {
        //show previous matches
      $eve_id = $_GET["id"];
      //get details of the event
      $q_events = "SELECT *, date_format(eve_date, '%W %D %b %Y') as FormatedDate FROM pd_events WHERE eve_id = $eve_id AND datediff(now(), eve_date) > $daysActive";
      $r_events = mysql_query($q_events);
      if(mysql_num_rows($r_events)==0)
      {
        echo "<script language=\"JavaScript\">window.location='event_matches.php'</script>";      
      }        
      while ($row = mysql_fetch_array($r_events)) 
      { 
      echo("<h2><span class=\"RedGbColor\">My Matches</span></h2><br />
<p><b>Event:</b> $row[eve_type_name], *$row[eve_ven_location]*, $row[eve_ven_name], $row[FormatedDate], $row[eve_time]<br/></p>");
      }

      //this is a list of other members who attended the event
      $query = "SELECT * FROM pd_booking AS p 
                  INNER JOIN pd_customers AS c ON c.cust_id = p.cust_id 
                  WHERE c.cust_email<>'$username' and p.eve_id = $eve_id
                  ORDER BY event_cust_id";

      $result= mysql_query($query);
      $matchCnt = 0;

      echo("
      <table width='390px' cellpadding=2 cellspacing=5>
      ");
      while ($row = mysql_fetch_array($result)) 
      { 
        if($row[photo]<>'' && $row[photo_approves] == 1)
        {
          $photoUrl = "photos/thumbs/photo$row[cust_id].jpg";
        }
        else
        {
          $photoUrl = "photos/thumbs/0.jpg";
        }
        $q_matched1 = "SELECT * FROM pd_event_match WHERE cust_id = $cust_id AND match_cust_id = $row[cust_id] and event_id = $eve_id";
        $r_matched1 = mysql_query($q_matched1);

        //check to see if they have matched back
        $q_matched2 = "SELECT * FROM pd_event_match WHERE cust_id = $row[cust_id] AND match_cust_id = $cust_id and event_id = $eve_id";
        $r_matched2 = mysql_query($q_matched2);        

        $match = false;
        if(mysql_num_rows($r_matched1)>0)
        {
          $info1 = mysql_fetch_array($r_matched1);
          if(mysql_num_rows($r_matched2)>0)
          {        
            $info2 = mysql_fetch_array($r_matched2);
            if($info1[want_date] == true && $info2[want_date] == True)
            {
              $matchStr = "Email Address: <a href='mailto:$row[cust_email]'>$row[cust_email]</a><br><br><span class='red'>DATE MATCHED!</span>";
              $match = true;
            }
            elseif($info1[want_friend] == true && $info2[want_friend] == True)
            {
              $matchStr = "Email Address: <a href='mailto:$row[cust_email]'>$row[cust_email]</a><br><br><span class='red'>FRIENDSHIP MATCHED!</span>";
              $match = true;
            }
            elseif($info1[want_date] == true && $info2[want_friend] == True)
            {
              $matchStr = "Email Address: <a href='mailto:$row[cust_email]'>$row[cust_email]</a><br><br><span class='red'>FRIENDSHIP MATCHED!</span>";
              $match = true;
            } 
            elseif($info1[want_friend] == true && $info2[want_date] == True)
            {
              $matchStr = "Email Address: <a href='mailto:$row[cust_email]'>$row[cust_email]</a><br><br><span class='red'>FRIENDSHIP MATCHED!</span>";
              $match = true;
            }                        
          }

        }

        if($match == true)
        {
        echo("<tr>
                <td valign='top'>
                  <p><b>$row[cust_first_names]</b><br/>
                  Candidate Number: $row[event_cust_id]<br/><br/>
                  $matchStr<br/>
                  $friendStr<br/></p>
                </td>
                <td align='right'>
                  <img src='$photoUrl' alt='$row[cust_first_names]'/>
                </td>
               </tr>
               <tr>
                <td colspan=2 style='height:4px;'><hr></td>
               </tr>
            ");
          $matchCnt = 1;
        }
        
        
      } 
      if($matchCnt == 0)
      {
         echo("<tr><td><p><br>Sorry, you had no matches for this event.</p></td></tr>");
      }
      echo("</table>");       
    }
    elseif($i>0 && $_GET["do"]<>"update") 
    {
      
    //show potential matches
      
      $eve_id = $_GET["id"];
      //get details of the event
      $q_events = "SELECT *, date_format(eve_date, '%W %D %b %Y') as FormatedDate FROM pd_events WHERE eve_id = $eve_id AND datediff(now(), eve_date) BETWEEN 0 AND 180";
      $r_events = mysql_query($q_events);
      if(mysql_num_rows($r_events)==0)
      {
        echo "<script language=\"JavaScript\">window.location='event_matches.php'</script>";      
      }

      while ($row = mysql_fetch_array($r_events)) 
      { 
      echo("<h2><span class=\"RedGbColor\">You have matched with...</span></h2><br />
<p><b>Event:</b> $row[eve_type_name], $row[eve_ven_location], $row[eve_ven_name], $row[FormatedDate], $row[eve_time]<br/><br/></p>");
      }
      
      $q_ticks = "SELECT sum(want_friend) AS friendTicks, sum(want_date) as dateTicks FROM pd_event_match WHERE event_id = $eve_id AND match_cust_id = $cust_id;";
      $r_ticks = mysql_query($q_ticks);
      $i_ticks = mysql_fetch_array($r_ticks);
      
      

      //this is a list of other members who attended the event
      $query = "SELECT * FROM pd_booking AS p 
                  INNER JOIN pd_customers AS c ON c.cust_id = p.cust_id 
                  WHERE c.cust_email<>'$username' and p.eve_id = $eve_id
                  ORDER BY event_cust_id";

      $result= mysql_query($query);


      echo("
      <p><b>In total you currently have $i_ticks[friendTicks] ticks for friendship, $i_ticks[dateTicks] ticks for dating.*</b><br/></p>
      
      <form action='event_matches.php?id=$eve_id&do=update' method='post' name='form1'>
      <table width='100%' cellpadding=2 cellspacing=0>
      ");
      while ($row = mysql_fetch_array($result)) 
      { 

        if($row[photo]<>'' && $row[photo_approves] == 1)
        {
          $photoUrl = "photos/thumbs/photo$row[cust_id].jpg";
        }
        else
        {
          $photoUrl = "photos/thumbs/0.jpg";
        }
        $q_matched1 = "SELECT * FROM pd_event_match WHERE cust_id = $cust_id AND match_cust_id = $row[cust_id] and event_id = $eve_id";
        $r_matched1 = mysql_query($q_matched1);

        //check to see if they have matched back
        $q_matched2 = "SELECT * FROM pd_event_match WHERE cust_id = $row[cust_id] AND match_cust_id = $cust_id and event_id = $eve_id";
        $r_matched2 = mysql_query($q_matched2);        

        if(mysql_num_rows($r_matched1)>0)
        {
          $info1 = mysql_fetch_array($r_matched1);
          if(mysql_num_rows($r_matched2)>0)
          {        
            $info2 = mysql_fetch_array($r_matched2);
            if($info1[want_date] == true && $info2[want_date] == True)
            {
              $matchStr = "Email Address: <a href='mailto:$row[cust_email]'>$row[cust_email]</a><br><br><span class='header'>DATE MATCHED!</span>";
            }
            elseif(($info1[want_friend] == true && $info2[want_friend] == True) || ($info1[want_date] == true && $info2[want_friend] == True)||($info1[want_friend] == true && $info2[want_date] == True))
            {
              $matchStr = "Email Address: <a href='mailto:$row[cust_email]'>$row[cust_email]</a><br><br><span class='header'>FRIENDSHIP MATCHED!</span>";
            }
            elseif($info1[want_friend] == true)
            {
              $matchStr = "Friendship Match pending...(awaiting $row[cust_first_names]'s tick).";
            }
            else
            {
              $matchStr = "Date Match pending...(awaiting $row[cust_first_names]'s tick).";
            }
          }
          elseif($info1[want_friend] == true)
          {
            $matchStr = "Friendship Match pending...(awaiting $row[cust_first_names]'s tick).";
          }
          else
          {
            $matchStr = "Date Match pending...(awaiting $row[cust_first_names]'s tick).";
          }
        }
        else
        {
          $matchStr = "<input type='radio' name='$row[cust_id]' groupname='grp$row[cust_id]' value='friend' onClick='enableSubmit();'>I want to be friends with this person.<br/>";
          $matchStr .= "<input type='radio' name='$row[cust_id]' groupname='grp$row[cust_id]' value='date' onClick='enableSubmit();'>I want to date this person.";
        }

        echo("<tr>
                <td valign='top'>
                  <p><b>$row[cust_first_names]</b><br/>
                  Candidate Number: $row[event_cust_id]<br/><br/>
                  $matchStr<br/>
                  $friendStr<br/></p>
                </td>
                <td align='right'>
                  <img src='$photoUrl' alt='$row[cust_first_names]'/>
                </td>
               </tr>
               <tr>
                <td colspan=2 style='height:4px;'><hr></td>
               </tr>
            ");
      }
      echo("<tr>
        <td colspan=2>
          <p><input type='submit' name='submit' disabled='true' id='submitBtn' value='Update My Matches' onClick=\"return(confirm('Are you sure as this action cannot be undone?'))\"/><input type='reset' value='Clear' onClick='disableSubmit();'/></p>
        </td>
    </tr>
</table><p><br/><br/>
       <sup>*</sup><i>Tick count is when someone has ticked you and includes people you may not have ticked back.<br/><br/> Dating ticks may include 
       ticks for dating that you may have ticked as friendship.<br/><br/>We do not give out any information if there has not 
        been a mutual match.</p></i> 
</form>");
    }
  // ************************ UPDATE & SEND EMAIL *****************************************    
    elseif($_GET["do"]=="update")
    {


      // **** INSERT MATCHES
      $q_details = "SELECT *, date_format(eve_date, '%D %b %Y – %W') as FormatedDate FROM pd_customers as c
          INNER JOIN pd_booking b ON c.cust_id = b.cust_id 
          INNER JOIN pd_events e ON e.eve_id = b.eve_id
          WHERE c.cust_email='$username'
          AND b.eve_id = $eve_id";

 
      $r_details = mysql_query($q_details);
      $i_details = mysql_fetch_array($r_details);

      $cust_fNames = $i_details [cust_first_names];
      $cust_event_id = $i_details[event_cust_id];
      $matchStr = ";".$cust_id.";";
      foreach($_POST as $key => $data) 
      {
        if($data=="friend")
        {
        $q_matching = "INSERT INTO pd_event_match (event_id, cust_id, match_cust_id, want_date, want_friend) VALUES ($eve_id, $cust_id, $key, false, true)";
        $r_matching = mysql_query($q_matching);   
        $matchStr .= $key .";";
        } 
        elseif($data=="date")
        {
        $q_matching = "INSERT INTO pd_event_match (event_id, cust_id, match_cust_id, want_date, want_friend) VALUES ($eve_id, $cust_id, $key, true, false)";
        $r_matching = mysql_query($q_matching); 
        $matchStr .= $key .";";
        }

      }

      //this is a list members who attended the event
      $q_allmatched = "SELECT DISTINCT c.cust_id, c.cust_first_names, c.cust_email, b.event_cust_id FROM pd_event_match AS me
               INNER JOIN pd_customers AS c ON c.cust_id = me.cust_id
               INNER JOIN pd_booking AS b ON b.cust_id = c.cust_id AND b.eve_id = me.event_id
               WHERE me.event_id = $eve_id AND (me.cust_id = $cust_id OR me.match_cust_id = $cust_id);";
      $r_allmatched= mysql_query($q_allmatched);

      //now we have to loop through all matches and  send all an email
      while($r = mysql_fetch_array($r_allmatched)) 
      {
        
        $cID = $r[cust_id];
        $pos = strrpos($matchStr, ";".$cID.";");
        if ($pos === false)
        {
        // not relavant to this member
        }
        else
        {  
        $cName = $r[cust_first_names];
        $cEmail = $r[cust_email];
        $cMEID = $r[event_cust_id];
        $cnt = 0;
        $tickFriend = 0;
        $tickDate = 0;
        $matchFriend = 0;
        $matchDate = 0; 
        $msgStrDate = "";
        $msgStrFriend = "";

        //check if any matches have happened and email the member
        $msgStr = "Dear $cName,<br/><br/>
        We hope you enjoyed the <span style='color:#AC2F82'>Pink</span>Date speed dating event in $i_details[eve_ven_name] on $i_details[FormatedDate]. Please find your matches so far below. 
        Should you have any queries please do not hesitate to contact us. <br/><br/><b>Match</b> = When two people have ticked each other (this is 
        when you will receive each others email and it is then up to you both to contact each other) <br/><br/>
        <b>Tick</b> = When someone has ticked you, but you may not have ticked them back (we do not give out any information if there has not 
        been a mutual match). <br/><br/>";      

        $query = "SELECT * FROM pd_event_match WHERE match_cust_id = $cust_id OR (cust_id = $cust_id AND  match_cust_id = $r[cust_id]) ";
        $result= mysql_query($query);
        $i = 0;
        while ($row = mysql_fetch_array($result)) 
        {   
          //check to see if anyone is interested in friendship with them
          $q_matched1 = "SELECT * FROM pd_event_match AS em
                 INNER JOIN pd_customers AS c ON c.cust_id = em.cust_id
                 INNER JOIN pd_booking AS b ON c.cust_id = b.cust_id AND em.event_id = b.eve_id
                 WHERE em.cust_id = $row[cust_id] AND match_cust_id = $cID";
          $r_matched1 = mysql_query($q_matched1); 

          while ($row1 = mysql_fetch_array($r_matched1)) 
          {

            if($row1[want_date] == true)
            {
              

              $q_matched2 = "SELECT * FROM pd_event_match AS em 
                 WHERE cust_id = $cID AND match_cust_id = $row1[cust_id] AND event_id = $eve_id";

              $r_matched2 = mysql_query($q_matched2);

              if(mysql_num_rows($r_matched2)>0)
              {
                while($row2 = mysql_fetch_array($r_matched2))
                {
                  if($row2[want_date] == true)
                  {
                    $matchDate  = $matchDate + 1;
                    $msgStrDate .= "
                      <tr>
                        <td><p>Number $row1[event_cust_id]</p></td>
                        <td><p>$row1[cust_first_names]</p></td>
                        <td><p>$row1[cust_email]</p></td>
                      </tr>
                     "; 
                  }
                  else
                  {
                    $matchFriend  = $matchFriend + 1;
                    $msgStrFriend .= "
                      <tr>
                        <td><p>Number $row1[event_cust_id]</p></td>
                        <td><p>$row1[cust_first_names]</p></td>
                        <td><p>$row1[cust_email]</p></td>
                      </tr>
                    ";                    
                  }
                  
                }
                       
              } 
              //else
              //{
                $tickDate = $tickDate + 1;
              //}
              

            }
            else
            {
              

              $q_matched2 = "SELECT * FROM pd_event_match AS em 
                 INNER JOIN pd_customers AS c ON c.cust_id = em.cust_id
                 WHERE c.cust_id = $cID AND match_cust_id = $row1[cust_id] AND want_friend = true AND event_id = $eve_id";                 
              $r_matched2 = mysql_query($q_matched2);
              if(mysql_num_rows($r_matched2)>0)
              {
               //loop here
               $matchFriend  = $matchFriend + 1;
               $msgStrFriend .= "
                <tr>
                  <td><p>Number $row1[event_cust_id]</p></td>
                  <td><p>$row1[cust_first_names]</p></td>
                  <td><p>$row1[cust_email]</p></td>
                </tr>
              "; 
              //loop end     
                
              }   
              //else
              //{
                 $tickFriend = $tickFriend + 1;
              //}
            }       
          } 
        }
        if($matchDate==0 && $matchFriend==0)
        {
          $msgStr .= "  
          <tr>
            <td colspan='3'><p><br/>Sorry, you currently have no matches.</p></td>
          </tr>";
        }
        else
        {
          $cnt = $matchFriend + $matchDate;
          $msgStr .= "  
          <h3>You have matched with $cnt people</h3>
          <table width='500'>
            <tr>
              <td><p><b>Candidate:</b></p></td>
              <td><p><b> </b></p></td>
              <td><p><b>Email Address:</b></p></td>
            </tr>
            <tr>
              <td class='highlight'><p>Number $cMEID</p></td>
              <td class='highlight'><p>$cName</p></td>
              <td class='highlight'><p>$cEmail</p></td>
          </tr>
          <tr>
            <td colspan='3'><p><br/>You matched with the following candidates:</p></td>
          </tr>";
          if($msgStrFriend<>"")
          {
            $msgStr .= "  
              <tr>
                <td colspan='3'><p><br/><b>Friendship Matches</b></p></td>
              </tr>".$msgStrFriend;
          }    
          if($msgStrDate<>"")
          {
            $msgStr .= "  
              <tr>
                <td colspan='3'><p><br/><b>Dating Matches</b></p></td>
              </tr>".$msgStrDate;
          }           
        }
        $msgStr .= "
      
    </table>
    <p>In total $cName you received $tickFriend ticks for friendship and $tickDate for dating.<br/><br/>
    Remember, number of ticks includes people who you may have not ticked and who've ticked you.<br/><br/>
    To view all of your matches for this event, click on this link:</p>
   <p><a href='http://www.pinkdate.co.uk/event_matches.php?id=$eve_id'>http://www.pinkdate.co.uk/event_matches.php?id=$eve_id</a></p>
    ";
    //if no results then don't send

          if($msgStrFriend<>"" || $msgStrDate<>"")
          {
          sendEmail($cEmail, "Pink Date Match Results Update!", $msgStr);
          }
         }
      }
      //echo "<script language=\"JavaScript\">window.location='./event_matches.php?id=$eve_id&do=match';</script>";
    }
    else
    {
     //echo "<script language=\"JavaScript\">window.location='event_matches.php;</script>";
    } 
    echo("<p><a href='event_matches.php'>Return to list of events</a></p>");     
  }

}
?>  
</div>
</div>
    <!--primary Content-->
    <div id="primaryContent">
    <?php include('includes/newEvents.php'); ?>
    </div>
    <!--Footer-->
<?php include('includes/footer.php'); ?>
  </div>
</div>
</body>
Link to comment
https://forums.phpfreaks.com/topic/287999-php-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.