Jump to content

[SOLVED] Checking a PHP variable in a JAVA scipt


ifis

Recommended Posts

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.