Kan ikke få skiftet:
$un = array("webwizo", "asif.iqbal", "demo1", "demo2", "demo3");
ud med:
$un = array("SELECT * FROM `medlemmer` WHERE `navn` = '".$username."'");
eller lign. Så den kan tjekke om navnet findes, hvis ja, optaget.
- <?php
-
- $action = $_POST['action'];
-
- if($action == 'check_username')
- {
- $u = $_POST['username'];
- _check_username($u);
- }
-
- function _check_username($u)
- {
- $un = array("SELECT * FROM `medlemmer` WHERE `navn` = '".$username."'");
- if(in_array($u, $un))
- {
- echo "<span class='no'><strong>{$u}</strong> is not available</span>";
- }
- else
- {
- echo "<span class='yes'><strong>{$u}</strong> is available</span>";
- }
- }
-
- ?>
--
Min komplet kode i redigering.
Ansogning:
- <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
-
- $("#brugernavn").blur(function() { // when focus out
-
- $("#message").html('Tjekker brugernavnet...'); //before AJAX response
-
- var form_data = {
- action: 'check_username',
- username: $(this).val()
- };
-
- $.ajax({
- type: "POST",
- url: "functions.php",
- data: form_data,
- success: function(result) {
- $("#message").html(result);
- }
- });
-
- });
-
- });
- </script>
-
-
- <input type="text" style="border-radius: 5px;" id="brugernavn" name="brugernavn" maxlength="25" AUTOCOMPLETE="Off" class="opretinput"/><br />
- <div id="message"></div>
functions.php
- <?php
- include("config.php");
- $action = $_POST['action'];
-
- if($action == 'check_username')
- {
- $u = $_POST['brugernavn'];
- _check_username($u);
- }
-
- function _check_username($u)
- {
- $un = mysql_query("SELECT * FROM `medlemmer` WHERE `navn` = '".$brugernavn."'");
- $un = array("".$un."");
- if(in_array($u, $un))
- {
- echo "<span class='no'><strong>{$u}</strong> optaget.</span>";
- }
- else
- {
- echo "<span class='yes'><strong>{$u}</strong> ledigt.</span>";
- }
- }
-
- ?>
Indlæg senest redigeret d. 02.07.2012 10:25 af Bruger #17281