/*This function is used to parse the input string and format them accordingly to meet the sql standard. In the case of text and double, single quote is placed around the string */ function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } //getting parameter informaiton from the querystring if there is any $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } /*if the user hit submit button, the $_POST("MM_insert"] is set to true the $insertSQL variable is then generated with the user input information */ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO scholarship (major, degree, gpa, scholarship, title, Lname, Fname, Mname, Address, Phone, Email, finNeed, addOn) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['major'], "text"), GetSQLValueString($_POST['degree'], "text"), GetSQLValueString($_POST['gpa'], "double"), GetSQLValueString($_POST['scholarship'], "text"), GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['lastname'], "text"), GetSQLValueString($_POST['firstname'], "text"), GetSQLValueString($_POST['middlename'], "text"), GetSQLValueString($_POST['address'], "text"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['need'], "text"), GetSQLValueString($_POST['addOn'], "date")); //select the database and execute the insert statement mysql_select_db($database_cs, $cs); $Result1 = mysql_query($insertSQL, $cs) or die(mysql_error()); //finding the person's information by finding the same social security number $query_aidT = sprintf("SELECT * FROM scholarship WHERE Fname = '%s' and Lname = '%s' and Phone = '%s'", $_POST['firstname'], $_POST['lastname'], $_POST['phone']); $aidT = mysql_query($query_aidT, $cs) or die(mysql_error()); $row_aidT = mysql_fetch_assoc($aidT); $totalRows_aidT = mysql_num_rows($aidT); //if the number is founded, automatically generates email message that contains the summary of the application if ($totalRows_aidT > 0 ) { $Lname = $row_aidT['Lname']; $Fname = $row_aidT['Fname']; $major = $row_aidT['major']; $scholarship = $row_aidT['scholarship']; $degree = $row_aidT['degree']; $gpa = $row_aidT['gpa']; $address = $row_aidT['Address']; $phone = $row_aidT['phone']; $email = $row_aidT['Email']; $finNeed = $row_aidT['finNeed']; $message = "Scholarship application\n\n"; $message = $message."Name: $Lname, $Fname\n"; $message = $message."Scholarship: $scholarship\n"; $message = $message."Major: $major\n"; $message = $message."Degree: $degree\n"; $message = $message."Current Address: $address\n"; $message = $message."Phone Number: $phone\n"; $message = $message."Email: $email\n\n"; $message = $message."Financial Need: $finNeed\n\n"; $headers = 'From: webmaster@cs.nmsu.edu' . "\r\n" . 'Bcc: kvillave@cs.nmsu.edu' . "\r\n" . 'ReplyTo: kvillave@cs.nmsu.edu'; //send the mail to the scholarhips coordinator mail("hue@cs.nmsu.edu", "Scholarship Request", $message, $headers); //send the email to the applicant mail("$email", "Scholarship Request", $message, $headers); } //redirect to the acholarAccepted.php page $insertGoTo = "scholarAccepted.php"; header(sprintf("Location: %s?tb_id=%d", $insertGoTo, $row_aidT['tb_id'])); } ?>