Jump to content

jonsjava

Members
  • Posts

    1,579
  • Joined

  • Last visited

Posts posted by jonsjava

  1. <?php‎
    include "base.php";
    $events = mysql_query("SELECT a.*, b.* FROM friendlist a INNER JOIN attend b ON (a.friendemail=b.email) WHERE a.email='$email' GROUP BY b.eventid ORDER BY count(*) DESC LIMIT 5");
    ?>

    You aren't executing the code. Nowhere do you actually call $events, which would then have PHP execute the query that resides in the variable. Also, you do nothing with the data it may return.

     

    Try this:

     

    <?php
    include "base.php";
    $sql = "SELECT a.*, b.* FROM friendlist a INNER JOIN attend b ON (a.friendemail=b.email) WHERE a.email='$email' GROUP BY b.eventid ORDER BY count(*) DESC LIMIT 5;";
    $res = mysql_query($sql) or die("Error!<br />".mysql_error());
    while ($row = mysql_fetch_assoc($res)){
    $out[] = $row;
    }
    var_dump($out);
    ?>

     

  2. Personally, I like having each page have the same template.  That means the body will be the only thing to change.  OK, maybe the menu bar will be context-sensitive, but a simple switch will handle all that:

    header.inc.php

    <?php
    function cleanInput($input){
    if (is_array($input)){
    	foreach ($input as $key=>$val){
    		$out[$key] = mysql_real_escape_string($val);
    	}
    }
    else{
    	$out = mysql_real_escape_string($input);
    }
    return $out;
    }
    if (isset($_GET['page']) && strlen($_GET['page']) >= 0){
    $page = cleanInput($_GET['page']);
    switch ($page){
    	case "home":
    		$title = "Welcome Home!";
    		brak;
    	case "edit":
    		$title = "Editing something.";
    		break;
    	case "cheeseburger":
    		$title = "Mmmmm...cheeseburger....*drool*";
    		break;
    	default:
    		$title = "I don't know what page you are on, but I bet you're having a good time!";
    }
    }
    else{
    $title = "I don't know what page you are on, but you shouldn't be here!";
    }
    //some HTML
    echo "<title>$title</title>";
    //the rest of your code
    ?>

  3. You need an .htaccess file first. A basic .htaccess file, for testing purposes:

     

    .htaccess

    AuthName "restricted stuff"
    AuthType Basic
    AuthUserFile /etc/.htpasswd
    require valid-user
    

    Place that file in the folder that you are wanting protected (or the root of the site, if you want ALL things protected)

     

    next, run this:

    htpasswd -c /etc/.htpasswd user1
    

    it will ask for a password for user1 (change the user to the username you want to use)

    for all other users, do this:

    htpasswd /etc/.htpasswd user2
    htpasswd /etc/.htpasswd user3
    etc...
    

     

  4. I hate to be the jerk, but you could do some of the coding. This is the "Help forum", not the "free labor" forum.  If you give us bad code, we will help you fix it -- gladly.  If you tell us to do all the work, you should be in the freelance section.

     

    edit Just noticed the freelance section is gone. Smeh. PM someone, and offer to pay them.

  5. I re-worked the logic a bit. Let me know if my assumptions were correct.

    <?php
    function cleanInput($POST){
    $out = array();
    foreach ($POST as $key=>$val){
    	$out[$key] = mysql_real_escape_string($val);
    }
    return $out;
    }
    function sendmail(){
    $cPOST = cleanInput($_POST);
    $cname = $cPOST['cname'];
    $sname = $cPOST['sname'];
    $fname = $cPOST['fname'];
    $contact = $cPOST['contact'];
    // If I understand your code, it looks like you are only pulling the contactflag for all the students. Why?
    $contactstudents = "SELECT contact_flag FROM student";
    $runcontact = mysql_query($contactstudents);
    $Name = "Student Course Registration"; //senders name
    $email = "goldie@telkomsa.net"; //senders e-mail adress
    $recipient = $_POST['email']; //recipient
    $mail_body = "Congratulations  $fname $sname. You have successfully registered for the		      
    					following course: $cname "; //mail body
    $subject = "Course registration successful!"; //subject
    $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
    //!!!!!!!!!!!!!!!!!!!Assuming $contact is a checkbox on the form !!!!!!!!!!!!!!!!!!!!!!!
    if (!isset($contact) || is_null($contact)){
    	mail($recipient,$subject,$mail_body,$header);
    }
    else{
    	$query = "SELECT sname,fname,email FROM student WHERE $contact = $runcontact";
    	$run = mysql_query($query) or die(mysql_error());
    	$contact_info = "";
    	while ($found = mysql_fetch_assoc($run))
    	{
    		$contactemail=$found['email'];
    		$contactsname=$found['sname'];
    		$contactfname=$found['fname'];
    		$contact_info .= "$contactsname, $contactfname, $contactemail\r\n";
    	}
    	$mail_body2 = "Congratulations  $fname $sname. You have successfully registered for the
    							following course: $cname. Here is a list of all the students 
    							who you may be in contact with: $contactsname, $contactfname, $contactemail"; //mail body for contact flag
    	mail($recipient, $subject, $mail_body2, $header);
    }
    }
    ?>
    

  6. try this (debugging code)

    <?php
    function sendmail(){
    $cname = mysql_real_escape_string($_POST['cname']);
    $sname = mysql_real_escape_string($_POST['sname']);
    $fname = mysql_real_escape_string($_POST['fname']);
    $contact = mysql_real_escape_string($_POST['contact']);
    $contactstudents = "SELECT contact_flag FROM student";
    $runcontact = mysql_query($contactstudents);
    $Name = "Student Course Registration"; //senders name
    $email = "goldie@telkomsa.net"; //senders e-mail adress
    $recipient = ($_POST['email']); //recipient
    $mail_body = "Congratulations  $fname $sname. You have successfully registered for the		      following course: $cname "; //mail body
    $subject = "Course registration successful!"; //subject
    $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
    if ($contact=="y"){
    	echo "Sending you mail_body2 because contact=y";
    	$query = "SELECT sname,fname,email FROM student WHERE $contact = $runcontact";
    	$run = mysql_query($query) or die(mysql_error());
    	while ($found = mysql_fetch_array($run))
    	{
    		$contactemail=$found['email'];
    		$contactsname=$found['sname'];
    		$contactfname=$found['fname'];
    		$mail_body2 = "Congradulations  $fname $sname. You have successfully registered for the following course: $cname. Here is a list of all the students who you may be in contact with: $contactsname, $contactfname, $contactemail"; //mail body for contact flag
    		mail($recipient, $subject, $mail_body2, $header);
    	}
    }
    else {
    	echo "sending you \$mail_body because \$contact=$contact";
    	mail($recipient, $subject, $mail_body, $header);
    }
    }
    ?>
    

×
×
  • 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.