Tutorijali.Net forum

Full Version: Ajax validacija
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Pozdrav svima. Prepravljao sam neku Ajax skriptu koja mi proverava da li je korisnicko ime i e mail zauzeto u bazi. E sad, meni skripta radi medjutim dobijam informaciju:

Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Ajax Validate (Beton)\check.php on line 19

Evo koda:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration form</title>
<script type="text/javascript">
<!--
var minlength = '3';
var delay = '1000';
var divid = 'username_exists';
function timeoutUsernameCheck(){
if(window.mytimeout) window.clearTimeout(window.mytimeout);
window.mytimeout = window.setTimeout("toggle_username()", delay);
return true;
}
function toggle_username() {
          if (window.XMLHttpRequest) {
        http = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    handle = document.getElementById('username');
    var url = 'check.php?';
    if(handle.value.length > minlength) {

                // Timestamp for preventing IE caching the GET request  
                fetch_unix_timestamp = function()  
                {  
                return parseInt(new Date().getTime().toString().substring(0, 10))  
                }  
                var timestamp = fetch_unix_timestamp();
        var fullurl = url + 'do=check_username_exists&username=' + encodeURIComponent(handle.value) + '&timestamp=' + timestamp;
        http.open("GET", fullurl, true);
        http.send(null);
        http.onreadystatechange = statechange_username;
    }else{
        document.getElementById(divid).innerHTML = '';
    }
}
function statechange_username() {

    if (http.readyState == 4) {

        var html = http.responseText;
        document.getElementById(divid).innerHTML = html;
            }
}
//-->
</script>
</head>
<body>
<p style="font-weight: bold;">Ajax provera korisnickog imena</p>
<br />
Rezultat poznat nakon<span style="font-weight: bold; color: green;"> 1 sekunde</span>; minimalan broj karaktera<span style="font-weight: bold; color: green;"> 4</span>.</p>
<div id="wrapper">
<div id="left" style="float: left; margin-right: 8px;">
<label for="username" style="margin-right: 6px;">Korisnicko ime: </label><input id="username" type="text" name="username" onkeyup="timeoutUsernameCheck()" size="20" style="display: inline;"/><br>
<label for="username" style="margin-right: 6px;">E-mail: </label><input id="username" type="text" name="email" onkeyup="timeoutUsernameCheck()" size="20" style="display: inline;"/><br>
<label for="username" style="margin-right: 6px;">Lozinka: </label><input id="username" type="text" name="sifra" onkeyup="timeoutUsernameCheck()" size="20" style="display: inline;"/>
</div>
<div id="username_exists" style="display: inline; font-size: 11px; font-weight: bold; color:#FF3300"> </div>
</div>
</body>
</html>

Evo check.php
Code:
<?php
// Connect to MySQL DB

mysql_connect ('localhost', 'root', '');
mysql_select_db('diplbaza');

$do = $_GET['do'];
switch($do)
{
case 'check_username_exists':
if(!get_magic_quotes_gpc())
{
$username = addslashes($_GET['username']);
}
else
{
$username = $_GET['username'];
}
$count = mysql_num_rows(mysql_query('SELECT * FROM check WHERE korime='.$username.''));
if($count > 0)
{

// Ako je korisnicko ime slobodno
echo '<img src="cross.jpg" alt="" width="22" height="22" />';
}
else
{

// Ako korisnicko ime nije dostupno

echo '<img src="check.jpg" alt="" width="22" height="22" />';

}
break;
default:
echo 'No action specified.';
break;
}
?>

I da linija 19 je ova:
Code:
$count = mysql_num_rows(mysql_query('SELECT * FROM check WHERE korime='.$username.''));
Hvala unapred
Pokusaj ovako:
PHP Code:
$count mysql_num_rows(mysql_query("SELECT * FROM check WHERE korime='".$username."'")); 
Probao ista poruka :(
Iskreno neda mi se sada gledati u kod, no imas slican (funkcionalan) primjer u mom tutorijalu:
http://www.tutorijali.net/forum/ajax-tut...-1325.html
Mozda da probas ovako :
PHP Code:
$count mysql_num_rows(mysql_query("SELECT * FROM check WHERE korime='$username'")); 
Ako ne provjeri dali sva polja su u bazi uredu tj da postoji tabela check u kojoj se nalazi polje korime.
Probao sam ali nece ni tako, mozda ima nesto sto trebam podesiti u php.ini u lokalu. Nemoguce da ovo ne radi.
@Zero probao sam i tvoj tutorijal i vraca mi istu gresku tj ovo za mysql_num_rows() funkciju. Znaci nije do skripte. Daniele naravno da postoji u bazi ova tabela.
PHP Code:
<?php
// Connect to MySQL DB

mysql_connect ('localhost''root''');
mysql_select_db('diplbaza');

$do $_GET['do'];
switch(
$do
{
case 
'check_username_exists':
if(!
get_magic_quotes_gpc()) 
{
$username addslashes($_GET['username']);
}
else
{
$username $_GET['username'];
}
$sql "SELECT * FROM check WHERE korime='$username'"
$nesto mysql_query('$sql'') or die('Ups' . mysql_error() . "<br />\n$sql");
$count = mysql_num_rows($nesto);
if($count > 0) 
{

// Ako je korisnicko ime slobodno
echo '
<img src="cross.jpg" alt="" width="22" height="22" />';
}
else
{

// Ako korisnicko ime nije dostupno

echo '
<img src="check.jpg" alt="" width="22" height="22" />';

}
break;
default:
echo '
No action specified.';
break;
}
?>


Nisam provjerio...
Imao si ovde par greskica tipa ; i "" ali ako to zanemarimo javi opet isto:

Ups: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check WHERE korime='admin'' at line 1
SELECT * FROM check WHERE korime='admin'.

Strasno
Probaj promjeniti ime tablice u check1 ili nesto sli─Źno.
Pa ne znam sta bi to moglo da promeni...
Pages: 1 2
Reference URL's