All pastes #2045449 Raw Edit

Anonymous

public text v1 · immutable
#2045449 ·published 2011-04-12 13:23 UTC
rendered paste body
 <?php

require('text.php');

//connect to the server

mysql_connect($s, $u, $p)
	or die ("We are currently having issues with our servers! - D'oh!.");
mysql_select_db($d);

if($_POST){

//validate email is @hud.ac.uk
if ( preg_match('/.+@hud\.ac\.uk$/i',  $email)  ) {
      die( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
	    <html>
	    <head>
	    <title>Musicians Database</title>
	    <meta http-equiv=\"REFRESH\" content=\\search.php\"></HEAD>
	    <BODY>
	    <font size=\"7\" color=\"red\">Must be a valid University of Huddersfield email address!</font>
	    </BODY>
	    </html>");
	    
      }

$search = trim(stripslashes($_POST['search']));
$email  = trim(stripslashes($_POST['email']));



//Find instruments searched for:




 	$query = "SELECT * FROM instruments WHERE '$search' IN (instrument, instrument2, instrument3, instrument4, instrument5)";

	$result = @mysql_query($query);

 



//Start building the table:

    $table = "<th> <p><b>You searched for $search</b></p></th> 
	
	<table>
  
	<th> <p><b>Name </b></p></th>
    <th> <p><b>Email </b></p> </th>
    <th> <p><b>Course </b></p></th>
    <th> <p><b>Grade </b></p></th>
    <th> <p><b>Standard </b></p></th>
    <th> <p><b>Comments</b></p></th></tr>";
    
   //Now get the person's name from the people table:
          
          while($getresults = mysql_fetch_assoc($result)){

          $peoplequery = "SELECT * FROM people WHERE id = {$getresults [id]}";
          $peopleresults = @mysql_query($peoplequery);
          $getpeopleresults = mysql_fetch_assoc($peopleresults);
    
  //add the details returned by the database to the table:
  
          $table .= "  
          <td><p>{$getpeopleresults [first]} {$getpeopleresults [last]}</p></td>
          <td><p>{$getpeopleresults [email]}</p></td>
          <td><p>{$getpeopleresults [course]}</p></td>
		  
		  
		  <td><p>{$getresults [grade]}</p></td>
          <td><p>{$getresults [standard]}</p></td>
          <td length=6000><p>{$getresults [comments]}</p></td></tr>
		  <tr><td colspan=8><hr size=1 color=gray></td></tr>
		  }
	  
	  ";
	    

}

$table .= "</table>";

//echo $table;

   // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
		$headers .= "From: Musicians Database";
		$to = ($_POST['email']);
		$subject = "Musicians Database Search";
		$body = "
		<html>
		$table</html>";

		if (mail($to, $subject, $body, $headers)) {
		header("Location:thanks.html");
		       exit();
		}

  
}
mysql_close($s, $u, $p); // close connection

?>


<head>



<script type="text/javascript">


//email address checking:

function validate_form(f){
  if (f.email.value.match(/^.+@hud\.ac\.uk$/)) {
		return true;
	} else {
		alert("Must be a valid University of Hudersfield email address!");
		return false;
	}
  
}
//-->
</script>


</head>


    
    <!-- MIKE'S CODE FOLLOWS!-->
    
    <?php

$inst_list = "SELECT instrument FROM instruments UNION SELECT instrument2 FROM instruments UNION SELECT instrument3 FROM instruments UNION SELECT instrument4 FROM instruments UNION SELECT instrument5 FROM instruments ORDER BY instrument
";


$list_result = @mysql_query($inst_list);

?>

<!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" dir="ltr">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>test</title>
	<link rel="stylesheet" href="css/general.css" type="text/css" media="screen" />
</head>
<body>
	<div id="container">
		<h1>Search Page</h1>

      <BR><BR><p><h3> Use the form below to search for a musician:</h3></p>
      <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>" onsubmit="return validate_form(this)";>


      <table align=left>
      <tr colsapn=2>&nbsp</tr>
      <tr><td><p><b>Instrument to Search For:</b></p></td>
      <td> <select name='search'>";

<?php

while($get_inst_list = mysql_fetch_assoc($list_result)){

      extract($get_inst_list);
      echo "<option value='$instrument'>$instrument";




}
?>

</td></tr>
<tr><td><p><b>Email Address: (MUST be your Uni Email) </b></p></td>
<td><input type='text' name='email'></td></tr>
<tr><td>&nbsp;</td></tr> 
<tr><td><center><input type='submit' value='Submit Search'></center></td></tr>
</table>
</form>

<!-- MIKE'S CODE ENDS -->

 </script>

</body>
</html>