php asincrono con ajax 2 campi di verifica

  • Creatore Discussione Creatore Discussione Gorlois
  • Data di inizio Data di inizio

Gorlois

Nuovo Utente
17 Ott 2013
7
0
0
salve, sto cercando di creare un form con 2 campi di veridica di dati (la verifica non deve essere sul singolo campo ma una volta che sono immessi entrambi):

Ho già il db creato, perchè viene sfruttato da un altro software, però non so come far corrispondere i dati con il db.
per esempio:

Nome db: bd1
Nome tabella: tabella
nome verifica campo 1 (sono numeri): id_numero
nome verifica campo 2 (idirizzo ip):id_ip

questi sono i file che ho e che non riesco a capire come modificarli:


dbconnection.php
Codice:
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "root";
$mysql_database = "databasename";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");

?>

check.php
Codice:
<?php

// This is a sample code in case you wish to check the username from a mysql db table

if(isSet($_POST['username']))
{
$username = $_POST['username'];

include("dbconnection.php");

$sql_check = mysql_query("SELECT user FROM {$prefix}users WHERE user='$username'");

if(mysql_num_rows($sql_check))
{
echo '<font color="red">The username <STRONG>'.$username.'</STRONG> is already in use.</font>';
}
else
{
echo 'OK';
}

}

?>

registration.php

Codice:
!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="en-us" http-equiv="Content-Language">

    <title>tiggin</title>
    
   <script src="js/jquery.js" type="text/javascript"></script>
	<script src="js/settings.js" type="text/javascript"></script>
<SCRIPT type="text/javascript">
pic1 = new Image(16, 16); 
pic1.src = "loader.gif";

$(document).ready(function(){

$("#username").change(function() { 

var usr = $("#username").val();

if(usr.length >= 3)
{
$("#status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...');

    $.ajax({  
    type: "POST",  
    url: "check.php",  
    data: "username="+ usr,  
    success: function(msg){  
   
   $("#status").ajaxComplete(function(event, request, settings){ 

	if(msg == 'OK')
	{ 
        $("#username").removeClass('object_error'); // if necessary
		$("#username").addClass("object_ok");
		$(this).html('&nbsp;<img src="accepted.png" align="absmiddle"> <font color="Green"> Available </font>  ');
	}  
	else  
	{  
		$("#username").removeClass('object_ok'); // if necessary
		$("#username").addClass("object_error");
		$(this).html(msg);
	}  
   
   });

 } 
   
  }); 

}
else
	{
	$("#status").html('<font color="red">The username should have at least <strong>3</strong> characters.</font>');
	$("#username").removeClass('object_ok'); // if necessary
	$("#username").addClass("object_error");
	}

});

});

//-->
</SCRIPT>

<style type="text/css">
body{
font-family:"Trebuchet MS";
font-size:12px;
}
.inn{
		float:left;
		font-size:14px;
		border:solid 1px #000000;
		width:143px;
		font-family:Arial, Helvetica, sans-serif;
		color:#0066CC;
		font-weight:bold;
		
		
		
	}
</style>
	  
  </head>
  
  <body>
 
	
	<table >
	      <tr>
        <td width="35%" align="right" valign="middle" id="abc">User Name  :</td>
        <td width="65%" align="left" valign="middle" ><input id="username"  type="text" name="username" onkeyup="twitter.updateUrl(this.value)" class="inn" />
          &nbsp; http://xyz.com/<span id="username_url"  style="color:#006600; font-weight:bold;">USERNAME</span> </td>
      </tr>
      <tr>
        <td></td>
        <td align="left" valign="bottom" height="20px"><div id="status"></div></td>
      </tr>
         </table>
	  
	
	<script type="text/javascript">


      $( function () {
        
  twitter.screenNameKeyUp();
  $('#user_screen_name').focus();

      });
    

</script>

  </body></html>
 

Discussioni simili