Reaper0167 Posted December 25, 2008 Share Posted December 25, 2008 i had a post a few days ago about a register script and we finally got that all figured out. but right now when the user doesn't fill in all three of the fields it directs them to another page with a message saying that the field was not filled in. and well, it just doesn't look professional. what i am hoping we can do is get the message to appear next to the field that was not filled in. i was told that this can not be done using PHP and javascript must be used. is that true? can anyone help me out here? thanks, Reaper. Oh yeh, here is what i got so far <?php //connection to your database include ("connection.php"); // define variables from register form $username = mysql_real_escape_string($_POST["username"]); $password = mysql_real_escape_string($_POST["password"]); $email = mysql_real_escape_string($_POST["email"]); $encrypted_password = md5($password); // display message if field is empty if (empty($username)) { echo "Please enter a username."; } elseif (empty($password)) { echo "Please enter a password."; } elseif (empty($email)) { echo "Please enter a valid email."; } else { // take user to a page after registration header("location:thanks.php"); } if (isset($_POST['submit'])) { // inserting data into your database $sql = "INSERT INTO $tbl_name(username, password, email)VALUES('$username','$encrypted_password','$email')"; $res = mysql_query($sql) or die(mysql_error()); // closes your connection mysql_close(); } ?> Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted December 25, 2008 Author Share Posted December 25, 2008 oh yeh,, here is my form <?php <form id="register" name="register" method="post" action="register.php"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="30%"><div align="right"> <label for="label3">Username</label> </div></td> <td width="70%"><input name="username" type="text" id="label3" size="35" maxlength="20" /></td> </tr> <tr> <td><div align="right">Password</div></td> <td><input name="password" type="password" id="label4" size="35" maxlength="20" /></td> </tr> <tr> <td height="22"><div align="right"> <label for="label4"></label> Email</div></td> <td><input name="email" type="text" id="label5" size="35" maxlength="65" /></td> </tr> <tr> <td height="22"> </td> <td><label for="submit"></label> <input type="submit" name="submit" id="submit" value="Register" /></td> </tr> </table> </form> ?> Quote Link to comment Share on other sites More sharing options...
dropfaith Posted December 25, 2008 Share Posted December 25, 2008 http://www.tizag.com/javascriptT/javascriptform.php pop up version Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted December 25, 2008 Author Share Posted December 25, 2008 thanks dropfaith.... i have been looking everywhere for this. Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted December 25, 2008 Author Share Posted December 25, 2008 acually, i'm not looking for a pop up window,,, just text that appears on the same page as my form. Quote Link to comment Share on other sites More sharing options...
liad Posted December 25, 2008 Share Posted December 25, 2008 Using PHP & AJAX can get you to a nice real-time form validation code. Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted December 26, 2008 Author Share Posted December 26, 2008 thanks,,,, gotta love that google page,,,,lol,,,,lol 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.