How to check which div is visible while scrolling?

How do I check if username already exists in database?

  • I need to check if username is already taken in database, can someone help me? Here's my full code: <?php include ('db_connect.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-… <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function validation() { var invalid = " "; // Invalid character is a space var minLength = 6; // Minimum length password var minLength2 = 4; //minimum length username var pw1 = document.create.password.value; var pw2 = document.create.password2.value; var name = document.create.name.value; // check for a value in both fields. if (pw1 == '' || pw2 == '') { alert('Please enter your password twice.'); return false; } //check for value in name if (document.create.name.value == "") { alert ("Username required"); return false; } // check for minimum length password if (document.create.password.value.length < minLength) { alert('Your password must be at least ' + minLength + ' characters long. Try again.'); return false; } // check for minimum length Username if (document.create.name.value.length < 4) { alert('Your username must be at least 4 characters long. Try again.'); return false; } // check for spaces password if (document.create.password.value.indexOf(… > -1) { alert("Your password may not contain any spaces."); return false; } // check for spaces username if (document.create.name.value.indexOf(inva… > -1) { alert("Your username may not contain any spaces."); return false; } else { if (pw1 != pw2) { alert ("You did not enter the same password twice. Please re-enter your password."); return false; } else { return true; } } } // End --> </script> </HEAD> </head> <body> <p> <?php if (isset ($_POST['Submit' ])) { $name = $_POST['name' ]; $password = $_POST['password' ]; $query = "INSERT INTO accounts (name, password) VALUES('$name', '$password')" ; mysql_query ($query );//kører forespørgsel mysql_close (); header ("location:confirm.php" ); } ?> </p><center><h1>Create account</h1></center><hr/> <center> <form id= "create" name="create" method= "post" onsubmit="return validation()" action="" > <table width= "310" border= "0" cellspacing= "" cellpadding= "0"> <tr> <td><b>Username:</b></td> <td><input type= "text" name="name" id="name" maxlength=12/></td> <tr><td><div class="validation">Min 4 - Max 12 characters. No special characters. No spaces.</div></td></tr> </tr> <tr> <td><b>Password:</b></td> <td><label> <input type="password" name="password" id="password" maxlength=12/> <tr><td><div class="validation">Min 6 - Max 12 characters. No special characters. No spaces.</div></td></tr> </label></td> </tr> <tr> <td><b>Repeat password:</b></td> <td><label> <input type="password" name="password2" id="password2" maxlength=12/> </label></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" id="Submit" value="Create account" /></td> </tr> </table> <hr/> </form> </center> </script> </body> </html>

  • Answer:

    Before inserting data make a SELECT query like: "SELECT * FROM accounts WHERE NAME='$name'" if this query will return an empty record set then this name doesn't exist.

Lukas at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.