lukeawade Posted September 10, 2008 Share Posted September 10, 2008 I have a registration page that if requires certain textfields be filled out. If they are not filled out or in the correct format then it displays an error on the same page under the textfield. If everything is filled out correctly it sends them an email and redirects them to a thankyou.html page. The problem I am having is I want to check if the email they entered exists in the database(this actually works but I cant get the error to display on the same page because I am using "die" but if i use echo i cant figure out how to get it to work) & if the email is real and if it exists in the database or the email isnt real then an error is displayed under the email textfield. I placed my code below but removed alot of the html code so that just the email field is displayed but all my precode is there. Thanks to all who can help. <?php require_once('../Connections/connRegistration.php'); ?> <?php // Load the common classes require_once('../includes/common/KT_common.php'); // Load the tNG classes require_once('../includes/tng/tNG.inc.php'); // Make a transaction dispatcher instance $tNGs = new tNG_dispatcher("../"); // Make a transaction dispatcher instance $tNGs = new tNG_dispatcher(""); // Make unified connection variable $conn_connRegistration = new KT_connection($connRegistration, $database_connRegistration); // Start trigger $formValidation = new tNG_FormValidation(); $formValidation->addField("first_name", true, "text", "", "", "", ""); $formValidation->addField("last_name", true, "text", "", "", "", ""); $formValidation->addField("company", true, "text", "", "", "", ""); $formValidation->addField("address1", true, "text", "", "", "", ""); $formValidation->addField("city", true, "text", "", "", "", ""); $formValidation->addField("state", true, "text", "", "", "", ""); $formValidation->addField("zip", true, "text", "zip_generic", "", "", ""); $formValidation->addField("phone", true, "text", "phone", "", "", ""); $formValidation->addField("cell_phone", false, "text", "phone", "", "", ""); $formValidation->addField("fax", false, "text", "phone", "", "", ""); $formValidation->addField("email", true, "text", "email", "", "", ""); $formValidation->addField("distribution_method", true, "distribution_method", "", "", "", ""); $tNGs->prepareValidation($formValidation); // End trigger //start Trigger_SendEmail trigger //remove this line if you want to edit the code by hand function Trigger_SendEmail(&$tNG) { $emailObj = new tNG_Email($tNG); $emailObj->setFrom("test@test.com"); $emailObj->setTo("{email}"); $emailObj->setCC(""); $emailObj->setBCC("test@test.com"); $emailObj->setSubject("Project Registration"); //WriteContent method $emailObj->setContent("{first_name}, <br><br> Thank you for registering. The Project Information Management Team <br><br><br><br> (Preferred Delivery Method: {distribution_method}) "); $emailObj->setEncoding("ISO-8859-1"); $emailObj->setFormat("HTML/Text"); $emailObj->setImportance("Normal"); return $emailObj->Execute(); } //end Trigger_SendEmail trigger 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; } } $colname_rsMail = "-1"; if (isset($_POST['email'])) { $colname_rsMail = $_POST['email']; } mysql_select_db($database_connRegistration, $connRegistration); $query_rsMail = sprintf("SELECT first_name, email FROM dashboard_registration WHERE email = %s", GetSQLValueString($colname_rsMail, "text")); $rsMail = mysql_query($query_rsMail, $connRegistration) or die(mysql_error()); $row_rsMail = mysql_fetch_assoc($rsMail); $totalRows_rsMail = mysql_num_rows($rsMail); // checks if the email is in the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $usercheck = $_POST['email']; $check = mysql_query("SELECT email FROM dashboard_registration WHERE email = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the email '.$_POST['email'].' has already registered.'); } // Make an insert transaction instance $ins_dashboard_registration = new tNG_insert($conn_connRegistration); $tNGs->addTransaction($ins_dashboard_registration); // Register triggers $ins_dashboard_registration->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1"); $ins_dashboard_registration->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation); $ins_dashboard_registration->registerTrigger("END", "Trigger_Default_Redirect", 99, "thankyou.html"); $ins_dashboard_registration->registerTrigger("AFTER", "Trigger_SendEmail", 98); // Add columns $ins_dashboard_registration->setTable("dashboard_registration"); $ins_dashboard_registration->addColumn("first_name", "STRING_TYPE", "POST", "first_name"); $ins_dashboard_registration->addColumn("last_name", "STRING_TYPE", "POST", "last_name"); $ins_dashboard_registration->addColumn("company", "STRING_TYPE", "POST", "company"); $ins_dashboard_registration->addColumn("address1", "STRING_TYPE", "POST", "address1"); $ins_dashboard_registration->addColumn("address2", "STRING_TYPE", "POST", "address2"); $ins_dashboard_registration->addColumn("city", "STRING_TYPE", "POST", "city"); $ins_dashboard_registration->addColumn("state", "STRING_TYPE", "POST", "state"); $ins_dashboard_registration->addColumn("zip", "STRING_TYPE", "POST", "zip"); $ins_dashboard_registration->addColumn("phone", "STRING_TYPE", "POST", "phone"); $ins_dashboard_registration->addColumn("cell_phone", "STRING_TYPE", "POST", "cell_phone"); $ins_dashboard_registration->addColumn("fax", "STRING_TYPE", "POST", "fax"); $ins_dashboard_registration->addColumn("email", "STRING_TYPE", "POST", "email"); $ins_dashboard_registration->addColumn("registration_date", "DATE_TYPE", "POST", "registration_date"); $ins_dashboard_registration->addColumn("ip", "STRING_TYPE", "POST", "ip"); $ins_dashboard_registration->setPrimaryKey("reg_id", "NUMERIC_TYPE"); $ins_dashboard_registration->addColumn("distribution_method", "STRING_TYPE", "POST", "distribution_method"); $ins_dashboard_registration->addColumn("proj_id", "INT_TYPE", "POST", "proj_id"); // Execute all the registered transactions $tNGs->executeTransactions(); // Get the transaction recordset $rsdashboard_registration = $tNGs->getRecordset("dashboard_registration"); $row_rsdashboard_registration = mysql_fetch_assoc($rsdashboard_registration); $totalRows_rsdashboard_registration = mysql_num_rows($rsdashboard_registration);?> <!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>Project Dashboard Registration</title> <?php echo $tNGs->displayValidationRules();?> </head> <body> <table width="525" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top" background="../Copy of jedunn/images/table_middle.gif"><table width="525" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="420" valign="top" class="norepeatbg"> <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>"> <div align="center"> <table width="402" align="center" cellpadding="2" cellspacing="0" > <tr> <td height="49" valign="top" class="style22" >*</td> <td valign="top" class="style2" ><label for="email"> <div align="left">E-mail:</div> </label></td> <td valign="top" class="style22"><div align="left"> <input name="email" type="text" id="email" value="<?php echo $row_rsdashboard_registration['email']; ?>" size="32" /> <?php echo $tNGs->displayFieldError("dashboard_registration", "email"); ?> </div></td> </tr> <tr> <td colspan="3" valign="top" class="style22" ><table width="337" border="0" align="center" cellpadding="0" cellspacing="0"> </table></td> </tr> </table> </div> <input type="hidden" name="proj_id" id="proj_id" value="23" /> <input type="hidden" name="registration_date" id="registration_date" /> <input type="hidden" name="ip" id="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" /> </form> </td> </tr> </table> </td> </tr> </table></td> </tr> </table> </body> </html> <?php mysql_free_result($rsMail); ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 10, 2008 Share Posted September 10, 2008 Trying to go through all of your code to see how to implement that would take a while. Instead I will provide a sample script that has the functionality you explained. Use it to modify your existing script: <?php if (isset($_POST['name']) || isset($_POST['email'])) { $name = trim($_POST['name']); $email = trim($_POST['email']); $nameError = false; $emailError = false; //Validate the name if (empty($name)) { $nameError = "You must enter a name."; } //Validate the email if (empty($email)) { $emailError = "You must enter an email."; } else { $query = "SELECT * FROM users WHERE email = '$email'"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result)!==0) { $emailError = "That email address already exists."; } } //Check for any errors if (!$nameError && !$emailError) { //Send email header('Location: http://www.mysite.com/thankyou.php'); exit(); } //Error exists, reformat values for repopulating fields $name = stripslashes($name); $email = stripslashes($email); } ?> <html> <head> </head> <body> <form name="testForm" method="POST"> Name: <input type="text" name="name" value="<?php echo $name; ?>" /><br /> <span style="color:red;"><?php echo $nameError; ?></span><br /> Email: <input type="text" name="email" value="<?php echo $email; ?>" /><br /> <span style="color:red;"><?php echo $emailError; ?></span><br /> <br /> <button type="submit">Submit Data</button> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
lukeawade Posted September 10, 2008 Author Share Posted September 10, 2008 One problem but other than that it looks like it will work. What if I already have a value set to a php script. The Code below is my code I'm currently using. Can I just put your <?php echo $email; ?> in with my <?php echo $tNGs->displayFieldError("dashboard_registration", "email"); ?> ?? //my code <html><input name="email" type="text" id="email" value="<?php echo $row_rsdashboard_registration['email']; ?>" size="32" /> <?php echo $tNGs->displayFieldError("dashboard_registration", "email"); ?></html> Quote Link to comment Share on other sites More sharing options...
lukeawade Posted September 10, 2008 Author Share Posted September 10, 2008 Also, I tried putting in your code like you said and commenting my old code and I'm getting the error message: No database selected Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 10, 2008 Share Posted September 10, 2008 As I said, going through all your code to figure out how to implement what you want would be time consuming. I only provided an example of how it could be accomplished. If you need someone to rewrite it for you then you could try the freelance forum. As for the database error - that is because the sample script doesn't include the code necessary to connect to the database. Again, it is just an example - the logic is sound. Quote Link to comment Share on other sites More sharing options...
lukeawade Posted September 10, 2008 Author Share Posted September 10, 2008 Thank you for your help. 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.