garydt Posted February 27, 2007 Share Posted February 27, 2007 When a new user registers an username that already exists i want an alert pop-up to say so instead of being redirected to another page and the user losing the data they've entered. I'm getting error- Parse error: parse error, unexpected '<' in C:\Program Files\xampp\htdocs\epeople\regformalert.php on line 46 The bit of code- // *** Redirect if username exists $MM_flag="MM_insert"; if (isset($_POST[$MM_flag])) { $loginUsername = $_POST['usenm']; $LoginRS__query = sprintf("SELECT usernm FROM userinformation WHERE usernm=%s", GetSQLValueString($loginUsername, "text")); mysql_select_db($database_elvisdb, $elvisdb); $LoginRS=mysql_query($LoginRS__query, $elvisdb) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, the username was found - can not add the requested username if($loginFoundUser){ //append the username to the redirect page <script language="javascript"> <!-- alert ("Username exists"); // --> </script> exit; } } Link to comment https://forums.phpfreaks.com/topic/40331-username-alert-pop-up/ Share on other sites More sharing options...
Yesideez Posted February 27, 2007 Share Posted February 27, 2007 Try this: <?php if($loginFoundUser){ //append the username to the redirect page echo ' <script language="javascript"> <!-- alert ("Username exists"); // --> </script>'; exit; } ?> Link to comment https://forums.phpfreaks.com/topic/40331-username-alert-pop-up/#findComment-195133 Share on other sites More sharing options...
nloding Posted February 27, 2007 Share Posted February 27, 2007 That code still requires a page refresh. Ajax will allow you to eliminate the need for a page refresh, but it is more work. To fix your current code, you were definitely missing the echo statement. For Ajax, you've got some more rewriting to do ... A couple articles to get you started the Ajax way (which is how I like to do it now ... and if the user has Javascript disabled, just build the check into the next page as a backup). http://www.mgroves.com/blog_archive.php?blogID=245 http://turnleft.inetsolution.com/2006/09/using_asp_and_ajax_to_check_av_1.html http://vyk1.spaces.live.com/Blog/cns!EBE3A761F939F926!1051.entry One of those uses ASP, but just rewrite the ASP parts in PHP and you're set. The Javascript remains the same except for the file it calls. Link to comment https://forums.phpfreaks.com/topic/40331-username-alert-pop-up/#findComment-195159 Share on other sites More sharing options...
garydt Posted February 27, 2007 Author Share Posted February 27, 2007 I will look at those. Thank you. Link to comment https://forums.phpfreaks.com/topic/40331-username-alert-pop-up/#findComment-195173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.