ifis Posted November 20, 2007 Share Posted November 20, 2007 I'm trying to check to see if a username in my databased is used before a form is submitted. I have created a simple JAVA scipt to check to see if a field in the form is filled out. I have also created a seperate php scipt to check if the username is already used. I would like to combine these two so a message is sent if the username is used before form submition to the server. Any suggestions? JAVA code: <script type='text/javascript'> function validate_required(field,alerttxt) { with (field) { if (value==null||value=='') {alert(alerttxt);return false} else {return true} } }function validate_form(thisform) { with (thisform) { if (validate_required(actype9,'actype9 must be filled out!')==false) {email.focus();return false} } } </script> <form method='POST' action='updateprofile.php' onsubmit='return validate_form(this)'> PHP code: //check is username already exists // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT loginName FROM $tbl_name WHERE loginName='$myusername'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername table row must be 1 row if($count==1){ echo "$myusername is already taken. Please choose another username."; } else { Thanks for help! Quote Link to comment https://forums.phpfreaks.com/topic/78121-solved-checking-a-php-variable-in-a-java-scipt/ Share on other sites More sharing options...
sKunKbad Posted November 25, 2007 Share Posted November 25, 2007 have javascript make a cookie from the username, and php can check to see if the cookie exists. That is the only way I know to get a variable between the two languages. Quote Link to comment https://forums.phpfreaks.com/topic/78121-solved-checking-a-php-variable-in-a-java-scipt/#findComment-398607 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.