Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Beginning Ajax with PHP From Novice to Professional phần 4 docx
Nội dung xem thử
Mô tả chi tiết
Similarly, your validator.php file now does much the same validation checking as
your autocomp.php file. This time, however, rather than checking for an exact match
against an array of names, the system now checks for an actual database match for the
name in question. Again, this is far superior, as you now have a means to properly store
information on saved names. Note that the code flow is largely the same, but now it is
done properly via a real data storage model, and the result is a nicely validated form (as
shown in Figure 4-4).
<?php
//validator.php
//Add in our database connector.
require_once ("dbconnector.php");
//And open a database connection.
$db = opendatabase();
//Set up the dynamic query string.
$querystr = "SELECT userid FROM user WHERE name = ➥
LOWER('" . mysql_real_escape_string ( $_GET['sstring']) . "')";
if ($userquery = mysql_query ($querystr)){
if (mysql_num_rows ($userquery) == 0){
//Then return with an error.
?><span style="color: #FF0000;">Name not found...</span><?php
} else {
//At this point we would go to the processing script.
?><span style="color: #FF0000;">Form would now submit...</span><?php
}
} else {
echo mysql_error();
}
?>
62 CHAPTER 4 ■ DATABASE-DRIVEN AJAX
6676CH04.qxd 9/27/06 11:53 AM Page 62