какой же ужас у вас создан. И плюс с проблемами безопасности.
<script type="text/javascript">
function hide() {
document.getElementById("resAuthCl").innerHTML = "";
}
function auth(f) {
var txt = f.elements["searchWord"].value;
if (txt == "") {
document.getElementById("resAuthCl").innerHTML = "Задан пустой запрос";
} else {
var elemsRadio = f.elements["authValue"];
var i, elem;
for (i=0; i<elemsRadio.length; ++i) {
if (elemsRadio[i].checked == true) {
elem = elemsRadio[i];
break;
}
}
var data = "txt="+txt+"&type="+elem.value;
var url = "other/forAuthClient.php?"+data;
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status >= 200 && this.status < 300 || this.status === 304) {
var perhapsJSON = null;
try {
if (window.JSON && JSON.parse) {
perhapsJSON = JSON.parse(this.responseText);
} else {
perhapsJSON = (new Function("return " + this.responseText))();
}
} catch(_e_) {}
if (perhapsJSON && perhapsJSON.found) {
document.getElementById("resAuthCl").innerHTML = 'Имя клиента: ' +
perhapsJSON.name + '<br />Телефон: ' + perhapsJSON.tel + '<br />' +
'<input id="postAndHide" type="button" value="Да, всё верно" onclick="hide();"/>';
} else {
document.getElementById("resAuthCl").innerHTML = "Запись не найдена";
}
}
}
};
request.send(null);
}
}
</script>
<body>
<div id="top"></div>
<form name="form1">
<input onkeydown="if (event.keyCode == 13) {auth(this.form); return false;}" id="searchWord" type="text" autofocus="autofocus" />
<input name="authValue" type="radio" value="tel" />по номеру
<input name="authValue" type="radio" value="code" checked />по Карте клиента
<input id="poisk" type="button" value="Найти" onclick="auth(this.form);"/>
</form>
<div id="resAuthCl"></div>
</body>
<?php
header("Content-Type: text/html; charset=WINDOWS-1251");
function clientAuth($text, $pole){
include('../block/db.php');
$res = mysql_query("select * from clients where $pole='" . mysql_real_escape_string($text) ."'", $db);
$numrows = mysql_num_rows($res);
if ($numrows > 0) {
$myrow = mysql_fetch_array($res);
return array(
'found' => true,
'name' => $myrow['name'],
'tel' => $myrow['tel'],
'skidka' => $myrow['skidka'],
'code' => $myrow['code'],
'kolvoObr' => $myrow['kolvo_obr'],
'sum' => $myrow['sum'],
);
}
return array('found' => false);
}
if (isset($_GET['txt'], $_GET['type'])) {
$text = $_GET['txt'];
$fl = array('found' => false);
session_start();
if ($_GET['type'] == 'tel') {
$fl = clientAuth($text, 'tel'); // в целях безопасности делать лучше так
} else if ($_GET['type'] == 'code') {
$fl = clientAuth($text, 'code'); // в целях безопасности делать лучше так
}
$_SESSION['auth'] = $fl;
session_write_close();
echo json_encode($fl);
}
?>