Hi AbraCadaver:
Thanks for the quick response. Even better, it is working on my page.
I do have question regarding the "COUNT(*)" select.
The previous developer used the DB_Sql class to implement all DB calls.
When I use the "Select Count" with DB_SQL it does not work, when I call "db1->f('count'), do you have any idea on how to use COUNT with DB_Sql?
I made it work with a regular "Select * from" and then check if the row count is above 0. It would be nice to know for the future. There should be also a performance difference between the 2, please correct me if I am wrong.
Here's the JS code that I actually used:
Code: Select all
var email = document.form1.email.value;
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "checkunique.php?email="+email, false);
xhttp.send();
var isTaken = xhttp.responseText;
if (isTaken > 0)
{
alert("This email address is already taken. Please choose a different email");
document.getElementById("email").focus();
return false;
}
The PHP that is called looks like that, the COUNT is commented out.
Code: Select all
<?php
session_start();
include("includes/common.php");
$isTaken = 0;
/*
// this one is not working...
if($_GET['email'])
{
$email = $_GET['email'];
$sql = "select count(*) from registeredusers where email='".$email."'";
$db1->query($sql);
$db1->next_record();
$isTaken = $db1->f('count');
}
*/
// this one is working
if($_GET['email'])
{
$email = $_GET['email'];
$sql = "select * from registeredusers where email='".$email."'";
$db1->query($sql);
$isTaken = $db1->num_rows();
}
echo $isTaken;
?>
Thanks again.
Regards
Thomas