debby87
04-06-2010, 16:26
Buongiorno,
sto progettando un'applicazione web che dā all'amministratore la possibilitā di cercare un utente nel database e se č presente, visualizzare tutti i suoi dati.
La funzione CercaUtente restituisce l'utente cercato dall'inserimento dell'Username. In gestionePOST voglio poter recuperare il return di existUsername, come posso fare?
controlloCercaUtente.js
function controllaUtente()
{
//controllo username
str = document.CercaUtente.username.value;
if (str.length == 0)
{
alert("Il campo username č vuoto");
document.CercaUtente.username.focus();
return;
}
if (confirm("Confermare ?"))
{
document.CercaUtente.method = "post";
document.CercaUtente.action = "GestionePOST.php";
document.CercaUtente.submit();
}
}
cercaUtente.tpl
<body>
<form name="CercaUtente">
<input type="hidden" name="formCercaUtente" value="1" />
<table class="tabellaForm" cellpadding="0" cellspacing="0">
<tr><th colspan="3"><span class="Stile45">CERCA UTENTE</span></th></tr>
<tr><td colspan="3" class="Stile45"> </td></tr>
<tr><td width=10% rowspan="5" class="Stile45"> <table></table></td></tr>
<tr>
<td align="left" class="Stile45"> Username:</td>
<td align="left" class="Stile45"><input type=text name="username" size=30 maxlength=20 value="{$username}"></td>
</tr>
<td colspan=3 class="Stile45"><input type="button" value='Invia' onClick="controllaUtente()"></td>
</table>
</form>
</body>
</html>
FUtente.class.php
<?php
require_once('Foundation\FControl.class.php');
require_once('Entity\EUtente.class.php');
require_once('Singleton.class.php');
class FUtente{
..
..
public function existUsername($user)
{
$mysqli=new FControl();
$sql= " SELECT *
FROM utente
WHERE username='{$user}' ;";
if($result=$mysqli->query($sql)){
if(($result->num_rows)==0){
$mysqli->close();
return false;
}
else{
$result=$result->fetch_assoc();
return new EUtente(
$result['CODICEUTENTE'],
$result['USERNAME'],
$result['PASSWORD'],
$result['RUOLO']);
}
}
else{
print("Ricerca username fallita:".$mysqli->error);
$mysqli->close();
exit();
}
}
..
..
}
CUtente.class.php
<?php
require_once('Foundation\FUtente.class.php');
require_once('Entity\ECliente.class.php');
require_once('Foundation\FCliente.class.php');
require_once('Entity\EUtente.class.php');
require_once('Session.class.php');
require_once('Control\MySmarty.class.php');
require_once('Singleton.class.php');
class CUtente{
..
..
function cercaUtente($username)
{
require_once("Foundation/FUtente.class.php");
require_once('Session.class.php');
$fCerca=Singleton::getInstance("FUtente");
}
..
}
e infine gestionePOST.php
if(isset($_POST['formCercaUtente']))
{
require_once('Control\CUtente.class.php');
$utente=Singleton::getInstance("FUtente");
$esiste=$utente->existUsername($_POST['username']);
}
Dove sbaglio???Non mi restituisce nessun utente trovato.
sto progettando un'applicazione web che dā all'amministratore la possibilitā di cercare un utente nel database e se č presente, visualizzare tutti i suoi dati.
La funzione CercaUtente restituisce l'utente cercato dall'inserimento dell'Username. In gestionePOST voglio poter recuperare il return di existUsername, come posso fare?
controlloCercaUtente.js
function controllaUtente()
{
//controllo username
str = document.CercaUtente.username.value;
if (str.length == 0)
{
alert("Il campo username č vuoto");
document.CercaUtente.username.focus();
return;
}
if (confirm("Confermare ?"))
{
document.CercaUtente.method = "post";
document.CercaUtente.action = "GestionePOST.php";
document.CercaUtente.submit();
}
}
cercaUtente.tpl
<body>
<form name="CercaUtente">
<input type="hidden" name="formCercaUtente" value="1" />
<table class="tabellaForm" cellpadding="0" cellspacing="0">
<tr><th colspan="3"><span class="Stile45">CERCA UTENTE</span></th></tr>
<tr><td colspan="3" class="Stile45"> </td></tr>
<tr><td width=10% rowspan="5" class="Stile45"> <table></table></td></tr>
<tr>
<td align="left" class="Stile45"> Username:</td>
<td align="left" class="Stile45"><input type=text name="username" size=30 maxlength=20 value="{$username}"></td>
</tr>
<td colspan=3 class="Stile45"><input type="button" value='Invia' onClick="controllaUtente()"></td>
</table>
</form>
</body>
</html>
FUtente.class.php
<?php
require_once('Foundation\FControl.class.php');
require_once('Entity\EUtente.class.php');
require_once('Singleton.class.php');
class FUtente{
..
..
public function existUsername($user)
{
$mysqli=new FControl();
$sql= " SELECT *
FROM utente
WHERE username='{$user}' ;";
if($result=$mysqli->query($sql)){
if(($result->num_rows)==0){
$mysqli->close();
return false;
}
else{
$result=$result->fetch_assoc();
return new EUtente(
$result['CODICEUTENTE'],
$result['USERNAME'],
$result['PASSWORD'],
$result['RUOLO']);
}
}
else{
print("Ricerca username fallita:".$mysqli->error);
$mysqli->close();
exit();
}
}
..
..
}
CUtente.class.php
<?php
require_once('Foundation\FUtente.class.php');
require_once('Entity\ECliente.class.php');
require_once('Foundation\FCliente.class.php');
require_once('Entity\EUtente.class.php');
require_once('Session.class.php');
require_once('Control\MySmarty.class.php');
require_once('Singleton.class.php');
class CUtente{
..
..
function cercaUtente($username)
{
require_once("Foundation/FUtente.class.php");
require_once('Session.class.php');
$fCerca=Singleton::getInstance("FUtente");
}
..
}
e infine gestionePOST.php
if(isset($_POST['formCercaUtente']))
{
require_once('Control\CUtente.class.php');
$utente=Singleton::getInstance("FUtente");
$esiste=$utente->existUsername($_POST['username']);
}
Dove sbaglio???Non mi restituisce nessun utente trovato.