Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ajax validacija
Author Message
stefendoza Offline
Redoviti posjetitelj
**

Posts: 81
Joined: Apr 2010
Reputation: 1
Post: #1
Ajax validacija
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
14-11-2010 03:13 PM
Find all posts by this user Quote this message in a reply
danielvast Offline
Forumaš
***

Posts: 432
Joined: Dec 2009
Reputation: 22
Post: #2
RE: Ajax validacija
Pokusaj ovako:
PHP Code:
$count mysql_num_rows(mysql_query("SELECT * FROM check WHERE korime='".$username."'")); 

"When all else fails, read the manual."
(This post was last modified: 14-11-2010 03:36 PM by danielvast.)
14-11-2010 03:33 PM
Find all posts by this user Quote this message in a reply
stefendoza Offline
Redoviti posjetitelj
**

Posts: 81
Joined: Apr 2010
Reputation: 1
Post: #3
RE: Ajax validacija
Probao ista poruka :(
14-11-2010 03:40 PM
Find all posts by this user Quote this message in a reply
zero Offline
Forumaš
***

Posts: 461
Joined: Jan 2008
Reputation: 10
Post: #4
RE: Ajax validacija
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

Brzo. Jeftino. Kvalitetno. Izaberi dva!
14-11-2010 03:55 PM
Find all posts by this user Quote this message in a reply
danielvast Offline
Forumaš
***

Posts: 432
Joined: Dec 2009
Reputation: 22
Post: #5
RE: Ajax validacija
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.

"When all else fails, read the manual."
14-11-2010 03:58 PM
Find all posts by this user Quote this message in a reply
stefendoza Offline
Redoviti posjetitelj
**

Posts: 81
Joined: Apr 2010
Reputation: 1
Post: #6
RE: Ajax validacija
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.
14-11-2010 04:21 PM
Find all posts by this user Quote this message in a reply
zero Offline
Forumaš
***

Posts: 461
Joined: Jan 2008
Reputation: 10
Post: #7
RE: Ajax validacija
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...

Brzo. Jeftino. Kvalitetno. Izaberi dva!
14-11-2010 04:31 PM
Find all posts by this user Quote this message in a reply
stefendoza Offline
Redoviti posjetitelj
**

Posts: 81
Joined: Apr 2010
Reputation: 1
Post: #8
RE: Ajax validacija
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
(This post was last modified: 14-11-2010 04:40 PM by stefendoza.)
14-11-2010 04:39 PM
Find all posts by this user Quote this message in a reply
danielvast Offline
Forumaš
***

Posts: 432
Joined: Dec 2009
Reputation: 22
Post: #9
RE: Ajax validacija
Probaj promjeniti ime tablice u check1 ili nesto slično.

"When all else fails, read the manual."
(This post was last modified: 14-11-2010 05:27 PM by danielvast.)
14-11-2010 04:54 PM
Find all posts by this user Quote this message in a reply
stefendoza Offline
Redoviti posjetitelj
**

Posts: 81
Joined: Apr 2010
Reputation: 1
Post: #10
RE: Ajax validacija
Pa ne znam sta bi to moglo da promeni...
14-11-2010 06:13 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)