sbinatl Posted February 8, 2018 Share Posted February 8, 2018 (edited) I have this code for an awards registration. It should go out to a table and verify the registrant is in a table named Tower_all. Next it makes sure the category is not full, not full should allow registration but it keeps getting pushed to a webform for if it is full either way. I'm sure something simple is there but I know just enough to be dangerous. The person handling this left and it just was handed to me yesterday to get working. Thanks so much in advance! <?php require_once('../Connections/xxxxx.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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; } } $id=$_GET['GTID']; $id=902150440; mysql_select_db($database_tower08, $tower08); $query_initial_info = "SELECT tower_all.id_char, tower_all.name_lfm, tower_all.major, tower_all.email, tower_all.awd_cat, tower_all.color, tower_all.awd_type FROM tower_all WHERE tower_all.id_char='$id'"; $initial_info = mysql_query($query_initial_info, $tower08) or die(mysql_error()); $row_initial_info = mysql_fetch_assoc($initial_info); $totalRows_initial_info = mysql_num_rows($initial_info); mysql_select_db($database_tower08, $tower08); $query_duplicate = "SELECT * FROM tower_reg WHERE tower_reg.gtid='$id' "; $duplicate = mysql_query($query_duplicate, $tower08) or die(mysql_error()); $row_duplicate = mysql_fetch_assoc($duplicate); $totalRows_duplicate = mysql_num_rows($duplicate); //Awd $awd_type=$row_initial_info['awd_type']; $awd_category=$row_initial_info['awd_cat']; //sustained count mysql_select_db($database_tower08, $tower08); $query_sustainedfull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='susta' AND tower_reg.answer = 'YES' "; $sustainedfull = mysql_query($query_sustainedfull, $tower08) or die(mysql_error()); $row_sustainedfull = mysql_fetch_assoc($sustainedfull); $totalRows_sustainedfull = mysql_num_rows($sustainedfull); $maxsust =200; //transfer count mysql_select_db($database_tower08, $tower08); $query_transferfull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='transfer' AND tower_reg.answer = 'YES' "; $transferfull = mysql_query($query_transferfull, $tower08) or die(mysql_error()); $row_transferfull = mysql_fetch_assoc($transferfull); $totalRows_transferfull = mysql_num_rows($transferfull); $maxtransfer =200; //yearly count mysql_select_db($database_tower08, $tower08); $query_yearlyfull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='yearl' AND tower_reg.answer = 'YES' "; $yearlyfull = mysql_query($query_yearlyfull, $tower08) or die(mysql_error()); $row_yearlyfull = mysql_fetch_assoc($yearlyfull); $totalRows_yearlyfull = mysql_num_rows($yearlyfull); $maxyearly =200; //grad count mysql_select_db($database_tower08, $tower08); $query_GRADfull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='grad' AND tower_reg.answer = 'YES' "; $GRADfull = mysql_query($query_GRADfull, $tower08) or die(mysql_error()); $row_GRADfull = mysql_fetch_assoc($GRADfull); $totalRows_GRADfull = mysql_num_rows($GRADfull); $maxGRAD =200; //masters count mysql_select_db($database_tower08, $tower08); $query_Mastefull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='maste' AND tower_reg.answer = 'YES' "; $Mastefull = mysql_query($query_Mastefull, $tower08) or die(mysql_error()); $row_Mastefull = mysql_fetch_assoc($Mastefull); $totalRows_Mastefull = mysql_num_rows($Mastefull); $maxMaste =800; //phd count mysql_select_db($database_tower08, $tower08); $query_phdfull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='phd' AND tower_reg.answer = 'YES' "; $phdfull = mysql_query($query_phdfull, $tower08) or die(mysql_error()); $row_phdfull = mysql_fetch_assoc($phdfull); $totalRows_phdfull = mysql_num_rows($phdfull); $maxphd =100; //freshmen count mysql_select_db($database_tower08, $tower08); $query_freshfull = "SELECT * FROM `tower_reg` WHERE tower_reg.awd_type='fresh' AND tower_reg.answer = 'YES' "; $freshfull = mysql_query($query_freshfull, $tower08) or die(mysql_error()); $row_freshfull = mysql_fetch_assoc($freshfull); $totalRows_freshfull = mysql_num_rows($freshfull); $maxfresh =200; switch ($awd_type) { case 'grad': if ($totalRows_GRADfull >= $maxGRAD) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; case 'phd': if ($totalRows_phdfull >= $maxphd) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; case 'transfer': if ($totalRows_transferfull >= $maxtransfer) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; case 'masters': if ($totalRows_Mastefull >= $maxMaste) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; case 'yearly': if ($totalRows_yearlyfull >= $maxyearly) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; case 'sustained': if ($totalRows_sustainedfull >= $maxsust) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; case 'freshmen': if ($totalRows_freshfull >= $maxfresh) { $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } break; default: echo "Award Type not found"; } //Sustained open closed? if ($totalRows_sustainedfull > $maxsust){ echo "BLAH"; $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //Freshmen open closed? if ($totalRows_freshfull > $maxfresh){ echo "BLAH"; $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //Yearly open closed? if ($totalRows_yearlyfull > $maxyearly){ $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //GRAD open closed? if ($totalRows_GRADfull > $maxGRAD){ $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //Masters open closed? if ($totalRows_Mastefull > $maxMaste){ $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //DDTRA open closed? if ($totalRows_transferfull > $maxtransfer){ $under_cap=false; header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //Are you Tower Eligible if ($row_initial_info == NULL){ header("Location: http://omed.gatech.edu/content/tower-full"); exit; } //Have you already registered if ($row_duplicate != NULL){ header("Location: http://www.omed.gatech.edu/tower/try_again.php"); exit; } //Phd open closed? if ($totalRows_phdfull > $maxphd){ header("Location: http://omed.gatech.edu/content/tower-full"); exit; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO tower_reg (gtid, info_change, answer, email, expected_grad, reason_not, confirm_num, color, tshirtsize, meal, awd_type, guest1, guest2 ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s)", GetSQLValueString($_POST['gtid'], "text"), GetSQLValueString($_POST['info_change'], "text"), GetSQLValueString($_POST['answer'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['expected_grad'], "text"), GetSQLValueString($_POST['reason_not'], "text"), GetSQLValueString($_POST['confirm_num'], "text"), GetSQLValueString($_POST['color'], "text"), GetSQLValueString($_POST['tshirtsize'], "text"), GetSQLValueString($_POST['meal'], "text"), GetSQLValueString($_POST['awd_type'], "text"), GetSQLValueString($_POST['guest1'], "text"), GetSQLValueString($_POST['guest2'], "text")); mysql_select_db($database_tower08, $tower08); $Result1 = mysql_query($insertSQL, $tower08) or die(mysql_error()); /*SEND CONFIRMATION EMAILS********************************************************* */ //Declare varibles for emails and confirmation page $email=$_POST['email']; $gtid=$_POST['gtid']; //Now send confirmation email $to=$email; $subject="Tower Awards Confirmation Email"; //Entire Message Body. Message body-Uses heredoc syntax <<< entire message including returns follows $message = <<<MSG TOWER AWARDS EMAIL ***DO NOT REPLY TO THIS EMAIL*** Congratulations: Student Number: $gtid!!! You have successfully completed the Tower Awards Registration. To view a detailed version of your confirmation go to www.omed.gatech.edu/tower If you registered as not attending you will receive an email one week after the awards ceremony with a decision and if approved where to pickup your award. To report a problem with the form or the website please send an email to tower@omed.gatech.edu Thank you MSG; //From must be included $from="From: DO_NOT_REPLY@omed.gatceh.edu"; //$itworked is a boolean value used to test for email errors below $itworked=mail ($to, $subject, $message, $from); //END of message**************************************************************************** // Guest e-mail if( filter_var($_POST['guest1'],FILTER_VALIDATE_EMAIL)){ $guest_email1 = $_POST['guest1']; }else{ $guest_email1 = ""; } if(filter_var($_POST['guest2'],FILTER_VALIDATE_EMAIL)){ $guest_email2 = $_POST['guest2']; }else{ $guest_email2 = ""; } $guest_to = $guest_email1 . ";" . $guest_email2; $guest_subject = "IMPORTANT: Your student has received A GT Tower Award!"; //TODO $guest_message = "Dear Parents and Family: Congratulations! YOUR student has achieved at least a 3.15 GPA during the past year and/or throughout his/her Georgia Tech career at one of the most academically competitive universities in the nation. For this milestone event, Georgia Tech, the Office of Institute Diversity, OMED: Educational Services and our corporate partners would like to honor their academic performance. OMED: Educational Services invites you to our celebration of academic excellence. The TOWER AWARDS continues to honor the achievements of our students. TOWER AWARDS: Date: Thursday, April 5, 2018 Time: 6:00 p.m. – 9:30 p.m. Place: Hyatt Regency Atlanta 205 Peachtree St, NE. NW Atlanta, GA 30303 During the Tower Awards, you can expect an elegant meal in the company of Georgia Tech students, our corporate partners, administrators, alumni, faculty and staff. The highlight of the evening is the recognition of your student for academic performance. We know that you would not want to miss this exciting opportunity to join us as we publicly declare how proud we are of your student’s accomplishments and the role you played. Every year we have overwhelming attendance from our students, faculty, and corporate sponsors, and we have reserved a select number of seats for family members. Due to space limitations, we ask that the number of guests be limited to two (not including the student being honored). Each ticket is $70.00, and seats will be reserved at the time payment is received. Please follow the registration and payment instructions at GT MarketPlace https://epay.gatech.edu/C20793_ustores/web/product_detail.jsp?PRODUCTID=1427 Your student must be confirmed as registered in order for family members to register and submit payment. Registered students will receive a confirmation email. The deadline for students to register to attend is Friday, March 8th, registration may close due to capacity limits. Family may only attend if the student has registered to attend. Each award category http://omed.gatech.edu/content/tower-eligibility will have a limited number of slots for attendees. Students will not receive awards unless they attend or provide a valid medical excuse. You will need your student's GT ID to register. The GT MarketPlace only accepts major credit card payments Visa, MC, Discover, and Amex. If your student is not registered to attend, your payment will not be processed. Using the GT MarketPlace is no different than ordering products from your favorite online retailer. The process is reasonably straight forward and very fast. To get started, simply click on the epay link above. We will close registration and payment for family members on Monday, March 19th, registration may close due to capacity limits. Should you have any questions regarding the event or registration, please contact tower@omed.gatech.edu. We look forward to seeing you on Thursday, April 5, 2018. Planning for Success, S. Gordon Moore Jr Interim Director, OMED: Educational Services "; // TODO if ($guest_to != "") mail ($guest_to, $guest_subject, $guest_message, $from ); // End Guest Message $insertGoTo = "thanks.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <?php //CONFIRMATION NUMBER GENERATOR function strrand($length,$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') { // Required Variables $string = ''; // Loop for($i = 0; $i <= $length-1; $i++) $string .= $chars[rand(0,strlen($chars)-1)]; // Return our random string. return $string; } ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Tower Registration</title> <style type="text/css"> <!-- .style1 { font-size: 24px; font-weight: bold; } #apDiv1 { position: absolute; left: 3px; top: 63px; width: 430px; height: 185px; z-index: 1; } body { background-image: url(); background-repeat: no-repeat; background-color: #996600; } .style2 { color: #FF0000; font-weight: bold; font-style: italic; } --> </style> </head> <body> <div align="center"> <table width="1503" border="0"> <tr> <td><p align="left" class="style1">Tower Awards Registration</p> <p><em><strong>Step 1: Please verify the Information, if it is not correct you can make changes below</em></strong></p> <p><strong>GTID:</strong> <?php echo $row_initial_info['id_char']; ?></p> <p><strong>Name:</strong> <?php echo $row_initial_info['name_lfm']; ?></p> <!--<p><strong>Test:</strong> 1:<?php echo $awd_type; ?> 2:<?php echo $awd_category; ?></p>--> <p><strong>Email:</strong> <?php echo $row_initial_info['email']; ?></p> <p><strong>Major:</strong> <?php echo $row_initial_info['major']; ?></p> <p><strong>Award Type:</strong> <?php echo $row_initial_info['awd_type']; ?></p> <p><strong>Award Category:</strong> <?php echo $row_initial_info['awd_cat']; ?></p> <p> </p> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="post"> <p><em><strong>Step 2: Please complete the following form</em></strong></p> <p><strong>TYPE YES IF IT IS CORRECT, IF THE ABOVE IS INCORRECT NOTE IT HERE. <a href="http://www.omed.gatech.edu/content/tower-eligibility">Tower type and category definitions.</a></strong> <p> <label><strong>This field cannot be left blank</strong> </br> <textarea name="info_change" id="info_change" cols="45" rows="5"></textarea> </label> </p> <p>Will you be attending the Tower Awards?</p> <p>If <strong>YES</strong>, please choose T-Shirt size, meal choice and <strong>THE EMAIL ADDRESS OF UP TO 2 </strong> guests you would like invitations emailed to.</p> <p>If <strong>NO</strong>, Explain below</p> <p> <label for="attending_0">Yes</label> <input type="radio" name="answer" value="YES" id="attending_0" /> </p> <p> <label for="attending_1">No</label> <input type="radio" name="answer" value="NO" id="attending_1" /> </p> <p><strong>IF YOU WILL NOT BE ATTENDING</STRONG> please give a <strong>BRIEF</strong> explanation. We will review all explanations after the Tower Awards. <p> <label><strong>Explanation</strong> </br> <textarea name="reason_not" id="reason_not" cols="45" rows="5"></textarea> </label> </p> </p> <p><strong>T-Shirt Size</strong> <p> <label> <input type="radio" name="tshirtsize" value="SM" id="tshirtsize" /> Small</label> <br /> <label> <input type="radio" name="tshirtsize" value="MED" id="tshirtsize_med" /> Med</label> <br /> <label> <input type="radio" name="tshirtsize" value="LG" id="tshirtsize_lg" /> Large</label> <br /> <label> <input type="radio" name="tshirtsize" value="XL" id="tshirtsize_xl" /> XL</label> <br /> <label> <input type="radio" name="tshirtsize" value="2XL" id="tshirtsize_2xl" /> 2XL</label> <br /> </p> <p><strong>Special meal preference</strong> <label> <input type="radio" name="meal" value="Vegetarian" id="Vegetarian" /> Vegetarian</label> <label> <input type="radio" name="meal" value="Vegan" id="Vegan" /> Vegan</label> <label> <input type="radio" name="meal" value="Gluten Free" id="Gluten_free" /> Gluten Free</label> <label> <input type="radio" name="meal" value="Nut Allergies" id="Nut_Allergies" /> Nut Allerigies</label> <input type="radio" name="meal" value="None" id="None" /> None</label> </p> <p><strong>Expected Graduation</strong> <label> <input type="radio" name="expected_grad" value="Spring 2018" id="spr18" /> Spring 2018</label> <label> <input type="radio" name="expected_grad" value="Summer 2018" id="sum18" /> Summer 2018</label> <label> <input type="radio" name="expected_grad" value="Fall 2018" id="fall18" /> Fall 2018</label> <label> <input type="radio" name="expected_grad" value="1plus" id="1plus" /> One or more years</label> </p> <SCRIPT language=JavaScript> <!-- //Accept terms & conditions script (by InsightEye www.insighteye.com) //Visit JavaScript Kit (http://javascriptkit.com) for this script & more. function checkCheckBox(f){ if (f.agree.checked == false ) { alert('Please check the box to continue.'); return false; }else return true; } //--> </SCRIPT> <form action="/yourscript.cgi-or-your-page.html" method="GET" onsubmit="return checkCheckBox(this)"> <!--Enter your form contents here--> <b>Photos will be taken, you must check the box confirming you have read and agree to the <a href="http://www.omed.gatech.edu/tower/release.pdf"taskid=$taskid" target="_blank">GT photo release</a> </b><br /> I accept: <input type="checkbox" value="0" name="agree"> <p><strong>You may invite two guests, please provide their <strong>EMAILS</strong> below so we can send them the invitation. </strong></p> <p> <label>Guest 1 EMAIL <input type="text" name="guest1" id="guest1" placeholder="email@example.com"> </label> </p> <p> <label>Guest 2 EMAIL <input type="text" name="guest2" id="guest2" placeholder="email@example.com"> </label> </p> <p> <input name="confirm_num" type="hidden" id="confirm_num" value="<?php echo strrand(7,'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');?>" /> <input name="email" type="hidden" id="email" value="<?php echo $row_initial_info['email']; ?>" /> <input name="gtid" type="hidden" id="gtid" value="<?php echo $row_initial_info['id_char']; ?>" /> <input name="color" type="hidden" id="color" value="<?php echo $row_initial_info['color']; ?>" /> <input name="awd_type" type="hidden" id="awd_type" value="<?php echo $row_initial_info['awd_type']; ?>" /> </p> <p> <input type="submit" name="button" id="button" value="SUBMIT FORM" /> </p> <input type="hidden" name="MM_insert" value="form1" /> </form></td> </tr> </table> </div> <div align="center"></div> <p align="center" class="style1"> </p> </body> </html> <?php mysql_free_result($initial_info); mysql_free_result($duplicate); ?> Edited February 9, 2018 by requinix please use [code] tags when posting code; minor edits Quote Link to comment Share on other sites More sharing options...
requinix Posted February 9, 2018 Share Posted February 9, 2018 There are too many "full" checks in there for us to make sense of it. Quite inefficient. Exactly which one(s) are you talking about? What are the values of assorted variables that are relevant/being used in the checks? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 9, 2018 Share Posted February 9, 2018 Most of that code is obsolete, some of it has been for well over a decade. It's too bad that, when he left, he didn't do you a favour and take it with him. My advice is throw it away and start again from scratch. Quote Link to comment Share on other sites More sharing options...
sbinatl Posted February 9, 2018 Author Share Posted February 9, 2018 There are too many "full" checks in there for us to make sense of it. Quite inefficient. Exactly which one(s) are you talking about? What are the values of assorted variables that are relevant/being used in the chec Last year when we used it it checked to see if they were in a table then checked to make sure their category was not already full. If so they could fill out the form. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 9, 2018 Share Posted February 9, 2018 Stop using the MySQL* functions. They are obsolete. Either start using the mysqlI* functions or the PDO ones. I'll never understand the concept of checking if a function exists or not and creating it if it doesn't. Why? Is it because of bad coding design that one has to check if a function has been written/included or what? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 9, 2018 Share Posted February 9, 2018 Stop using the MySQL* functions. They are obsolete. Either start using the mysqlI* functions or the PDO ones. I'll never understand the concept of checking if a function exists or not and creating it if it doesn't. Why? Is it because of bad coding design that one has to check if a function has been written/included or what? this is dreamweaver produced code and that's how bad it is. it bruit force builds code for each thing you do on a page and it has no knowledge of what else the code is doing, so, there's no finesse to the code and there's all kinds of unnecessary code cluttering up what is really gong on, on the page. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 9, 2018 Share Posted February 9, 2018 i'm going to guess that all of the category limits have been reached, and since the code wasn't written to specifically report which test has failed, it isn't providing any useful feedback. code should produce and output unique and specific error messages for any validation, operation, or test that fails. Last year ... an application that's used on periodic data needs to store the date as part of the data and use the current date when operating on data. also, the things that are date dependent in the output/email need to either be produced dynamically from the current date or implemented as variable/defined-constant settings, with the settings either near the top of the code or as a separately 'required' file. --- if you are doing this for real, i.e. this is more than just a programming class assignment, you should probably hire a programmer to write the application from scratch using current and secure programming practices. if you are doing this as a programming class assignment, 1) forget about using dreamweaver, 2) start by defining the requirements, 3) then write and test just the necessary code needed for the application, one small step at a time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.