amit_n Posted October 15, 2008 Share Posted October 15, 2008 Hi, I have "registration form" in Html. This form has text fields like loginid, password, email, address, zip, etc. I want to check the loginid is available or not before submitting the form. For that i have given following link in html form just below to the loginid text field. <div align="left"><a href="checkid.php?action=CheckID">Check the availability</a></div> And checkid.php has following code. <?php $loginid = $_POST['loginid'];mysql_connect("localhost", "root") or die("Cannot connect to DB!");mysql_select_db("loginsys") or die("Cannot select DB!");$r = mysql_query("SELECT * FROM login_tbl where loginid='$loginid';");$numrow = mysql_num_rows($r);if ($numrow == 0){print "This UserID is available";include "register1.html";}else{print "This UserID is not available";} ?> But the problem is after selecting the link for checkid.php the $_POST['loginid'] is considered as blank. This is may be because I am not submitting the form. Is there any other way to get $_POST['loginid'] value without choosing the submit button? Can i pass the value of $_POST['loginid'] without choosing the submit button? [/] Quote Link to comment Share on other sites More sharing options...
amites Posted October 15, 2008 Share Posted October 15, 2008 you could do it with AJAX working on any part without changing the page is all about AJAX Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted October 15, 2008 Share Posted October 15, 2008 yeah you could use ajax. If you would lik to stick with php for nw u can do that too witha little bit of javascript. The form can be divided into two. have the login filed in a separate form and the rest of the fields in another form eg: <?php if(isset($_POST["check"])) { $user = $_POST["user"]; } ?> <form action="register.php" method="POST" name="form1"> <tr> <td class="textsr">Username*</td><td><input name="user" type="text" class="textbox" value="<?php echo $user;?>"> <input name="check" type="submit" value="check availability" class="button"> </td> <tr> <td></td> <td class="textsr"> <?php if(isset($_POST["check"]) && ($_POST["user"]!="") && (trim($_POST["user"])!='')) {$user=trim($_POST["user"]); $res=mysql_query("select * from table where username='$user'"); $trows=mysql_num_rows($res); if($trows==0) { echo "<font color='green'>The username is available</font>"; } else { echo "<font color='red'>The username is not available.<br>Please select another one</font>"; } }else { echo ""; } ?> </td> </form> This way you can have the message appear right under the username box. Quote Link to comment Share on other sites More sharing options...
amit_n Posted October 15, 2008 Author Share Posted October 15, 2008 Thank you so much 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.