Ciao a tutti. Non so se questa è la sezione corretta del forum su cui scrivere, spero di si.
Ho scritto un codice php con anche dell'xml, perchè vorrei ottenere questo risultato:
http://www.danieletabacco.com/esempi/esempio_php02.php
Premetto che il codice che scrivo qui sotto l'ho "copiato" dal sito sopra, ma vorrei cambiarlo in modo che invii i dati tramite xml al database e riceva risposta con ajax.(tutto tramite POST perchè deve essere sicuro).
Ho provato a modificarlo per la mia esigenza ma non funziona perchè non mi fa comparire la tabella con tutti i campi, ma solo la finestra con l'opzione dei nomi.
il codice originale lo potete trovare qui:
http://www.danieletabacco.com/18/art...jax-e-php.html
Cmq per praticità ve lo posto qui sotto comunque...
provasito.php
Codice PHP:
<script type="text/javascript">
var xmlhttp;
function mostraInfo(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="mostra_utenti.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("info").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
<form>
Seleziona Dipendente:
<select name="users" onChange="mostraInfo(this.value)">
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
//Seleziono quelli che sono i dipendenti
$connessione = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $connessione);
$query = "SELECT * FROM user ";
$result = mysql_query($query);
while($riga = mysql_fetch_array($result)){
echo "<option value='$riga[user_id]'>$riga[user_firstname] $riga[user_lastname]</option>";
}
?>
</select>
</form>
<div id="info"></div>
Codice PHP:
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
$q=$_GET["q"];
$con = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $con);
$sql="SELECT * FROM dipendenti WHERE id = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>Anni</th>
<th>Lavoro</th>
<th>Stipendio</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['user_firstname'] . "</td>";
echo "<td>" . $row['user_lastname'] . "</td>";
echo "<td>" . $row['user_username'] . "</td>";
echo "<td>" . $row['user_password'] . "</td>";
echo "<td>" . $row['user_email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
invece metto il codice dei miei file modificati qui:
questo file l'ho chiamato: provasito.php
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Post</title>
</head>
<body>
<div id="xmldata"></div>
<script type="text/javascript">
function readyAJAX() {
try {
return new XMLHttpRequest();
} catch(e) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
return "A newer browser is needed.";
}
}
}
}
var requestObj = readyAJAX();
var url = "mostra_utenti.php";
var params = "q=25";
requestObj.open("POST",url,true);
requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
requestObj.send(params);
requestObj.onreadystatechange = function() {
if (requestObj.readyState == 4) {
if (requestObj.status == 200) {
alert(requestObj.responseText);
} else {
alert(requestObj.statusText);
}
}
}
</script>
<form>
Seleziona Dipendente:
<select name="users" onChange="mostraInfo(this.value)">
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
//Seleziono quelli che sono i dipendenti
$connessione = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $connessione);
$query = "SELECT * FROM user ";
$result = mysql_query($query);
while($riga = mysql_fetch_array($result)){
echo "<option value='$riga[user_id]'>$riga[user_firstname] $riga[user_lastname]</option>";
}
?>
</select>
</form>
<div id="info"></div>
</body>
</html>
questo invece è il file: mostra_utenti.php :
Codice PHP:
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
$q=$_POST['params'];
$con = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $con);
$sql="SELECT *
FROM user
WHERE user_id = '".$q."'";
$result = mysql_query($sql);
if ($sql!==false) {echo "non va la query";}
echo "<table border='1'>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['user_firstname'] . "</td>";
echo "<td>" . $row['user_lastname'] . "</td>";
echo "<td>" . $row['user_username'] . "</td>";
echo "<td>" . $row['user_password'] . "</td>";
echo "<td>" . $row['user_email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Ah, dimenticavo! Ovviamente ho provato con il codice originale e funziona, perciò non è un problema di connessione al database o cose simili ;P
Qualcuno mi può aiutare??? 
Grazie, aspetto con ansia