lukeawade Posted September 16, 2008 Share Posted September 16, 2008 The PROBLEM is I need to display two different error messages based on the information in one textfield. If there is nothing in the textfield it shows an error based on the tNG_formvalidation(WORKS), the second error shows if their email already exists in the database(DOESNT WORK) There is no error displayed using the code below. It just redirects to the next page(like its supposed to if there is an email in the textfield). The $database_connRegistration is set and works for everything else I'm doing. Here is where i create the email error if its in the database already <?php $colname_rsMail = "-1"; if (isset($_POST['email'])) { $colname_rsMail = $_POST['email']; mysql_select_db($database_connRegistration, $connRegistration); $query_email = sprintf("SELECT email FROM dashboard_registration WHERE email = '$email'"); $email = mysql_query($query_email, $connRegistration) or die(mysql_error()); $emailError = false; if (mysql_num_rows($email)!== 0) { $emailError = "That email address has already been registered."; } //Error exists, reformat values for repopulating fields $email = stripslashes($email); }?> NOW how do I display that under the Textfield/Input when there is already an echo error?? <input name="email" type="text" id="email" value="<?php echo $row_rsdashboard_registration['email']; echo $emailerror;?>" size="32" /> <?php echotNGs->displayFieldError("dashboard_registration", "email"); echo $emailError;?> Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/ Share on other sites More sharing options...
akitchin Posted September 16, 2008 Share Posted September 16, 2008 <input name="email" type="text" id="email" value="<?php echo $row_rsdashboard_registration['email']; echo $emailerror;?>" size="32" /> see anything funny about that variable name? perhaps a missing capital letter? Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643326 Share on other sites More sharing options...
fanfavorite Posted September 16, 2008 Share Posted September 16, 2008 You have "echo $emailerror" inside your input tag. Is this on purpose? You haven't showed the variable $emailerror (not same as $emailError). "echo $emailError" is listed below, which should show "That email address has already been registered." if the email has been. I don't see a redirect. "$email" is not defined when using it in your mysql query (unless you are still using PHP4 or less and your PHP settings allow you to do so). You should really use $_POST['email'] Seems that there is a lot of information that is missing that needs to be shown in order to fix your problem. Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643331 Share on other sites More sharing options...
akitchin Posted September 16, 2008 Share Posted September 16, 2008 i agree that there is some information missing, but i would guess it's because your query returns no rows. that's because, as fanfavorite said, $email won't exist unless register_globals is on. if you want a quick (and dirty) fix, change $email in the query to $colname_rsMail. Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643334 Share on other sites More sharing options...
lukeawade Posted September 16, 2008 Author Share Posted September 16, 2008 Here is what I just tried. Still does not work. In The Precode <?php $colname_rsMail = "-1"; if (isset($_POST['email'])) { $colname_rsMail = $_POST['email']; mysql_select_db($database_connRegistration, $connRegistration); $query_email = sprintf("SELECT email FROM dashboard_registration WHERE email = '$colname_rsMail'"); $email = mysql_query($query_email, $connRegistration) or die(mysql_error()); $emailError = false; if (mysql_num_rows($email)!== 0) { $emailError = "That email address has already been registered."; } //Error exists, reformat values for repopulating fields $email = stripslashes($email); }?> In the Body <input name="email" type="text" id="email" value="<?php echo $row_rsdashboard_registration['email'];?>" size="32" /> <?php echo $emailError; echo $tNGs->displayFieldError("dashboard_registration", "email");?> Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643342 Share on other sites More sharing options...
thesaleboat Posted September 16, 2008 Share Posted September 16, 2008 if (mysql_num_rows($email)!== 0) { $emailError = "That email address has already been registered."; } Try if (!mysql_num_rows($email) == 0) { $emailError = "That email address has already been registered."; } Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643352 Share on other sites More sharing options...
thesaleboat Posted September 16, 2008 Share Posted September 16, 2008 ^ They might be the same im not sure... but also... what is sprintf? instead of $query_email = sprintf("SELECT email FROM dashboard_registration WHERE email = '$colname_rsMail'"); Use $query_email = mysql_query("SELECT email FROM dashboard_registration WHERE email = '$colname_rsMail'"); Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643354 Share on other sites More sharing options...
trq Posted September 16, 2008 Share Posted September 16, 2008 Actually sprintf is a good choice for building a query, nopt that it has been put to any use in this occassion though. Should be.... $query_email = sprintf("SELECT email FROM dashboard_registration WHERE email = '%s'", $colname_rsMail); Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643356 Share on other sites More sharing options...
lukeawade Posted September 17, 2008 Author Share Posted September 17, 2008 Thank you for all the responses. I tried them and it still doesnt work. Here is what I have now. <?php $colname_rsMail = "-1"; if (isset($_POST['email'])) { $colname_rsMail = $_POST['email']; mysql_select_db($database_connRegistration, $connRegistration); $query_email = sprintf("SELECT email FROM dashboard_registration WHERE email = '%s'", $colname_rsMail); $email = mysql_query($query_email, $connRegistration) or die(mysql_error()); $emailError = false; if (mysql_num_rows($email) !== 0) { $emailError = "That email address has already been registered."; } //Error exists, reformat values for repopulating fields $email = stripslashes($email); } In the head & body <head><?php echo $tNGs->displayValidationRules(); echo $emailError;?></head> <body> <input name="email" type="text" id="email" value="<?php echo $row_rsdashboard_registration['email'];?>" size="32" /> <?php echo $emailError; echo $tNGs->displayFieldError("dashboard_registration", "email");?> </body> Link to comment https://forums.phpfreaks.com/topic/124554-expert-help-please/#findComment-643737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.