Pagina 2 di 3 primaprima 1 2 3 ultimoultimo
Visualizzazione dei risultati da 11 a 20 su 21
  1. #11
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Allora quello dei posti era solo un esempio, ammetto di aver fatto un po' di confusione...

    Io vorrei fare inserire dati di ad esempio un numero tramite dei form e inviare questi dati criptati in xml al database che controlla l'esistenza di questo numero e se esiste allora manda una risposta in ajax dicendo che esiste. Come faccio?
    Ho provato a fare le modifiche che mi hai detto, apparte che cmq il codice che ho fatto io non fa quello che ti ho scritto sopra,come potrei modificarlo per far quello sopra?


    Ho provato così,ma non funziona, non mi legge quello che è dentro il div info


    provasito2.php
    codice:
    <!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 "Hai bisogno di un altro browser."; 
            } 
        } 
    } 
    } 
    
    function mostraInfo(data)
    {
    var requestObj = readyAJAX(); 
    var url = "mostra_utenti_prova.php"; 
    var params = "q=" + data;
    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) { 
    		var a=(requestObj.responseText);
                document.getElementById('info').innerHTML = a;
            } else { 
                alert(requestObj.statusText); 
            } 
        } 
    } 
    }
    </script> 
    <form>
    <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">
    
      var serverResponse = requestObj.responseXML;
       var header = serverResponse.getElementsByTagName("user");
    
       htmlString = "<table><tr><th>Nome</th><th>Cognome</th><th>Username</th><th>Password</th><th>Email</th></tr>";
    		
       for (i=0; i<header.length; i++)
       {
          htmlString += "<tr>";
          if (window.ActiveXObject)
          {
             htmlString += "<td>" + header[i].childNodes[0].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[3].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[4].text + "</td>";
          }
          else
          {
             htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[3].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[4].textContent + "</td>";
          }
          htmlString += "</tr>";
       }
       htmlString += "</table>";
    
       document.getElementById('info').innerHTML = htmlString;    
    
    </div> 
    
    </body> 
    </html>

    mostra_utenti_prova.php

    codice:
    <?php 
    header('Content-Type: text/xml');
    
    $db_host = "localhost"; 
    $db_user = "administrator"; 
    $db_password = "administrator"; 
    $db_database = "ticket"; 
    
    
     $q=$_POST['q']; 
    
    $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); 
    
    $xml = new DomDocument('1.0'); 
        $info = $xml->createElement('informations'); 
        $info = $xml->appendChild($info); 
    
        while ($row = mysql_fetch_array($result)) 
        { 
            $firstname = $xml->createElement('firstname'); 
            $firstname = $info->appendChild($firstname); 
            $value = $xml->createTextNode($row['user_firstname']); 
            $value = $firstname->appendChild($value); 
                 
            $lastname = $xml->createElement('lastname'); 
            $lastname = $info->appendChild($lastname); 
            $value = $xml->createTextNode($row['user_lastname']); 
            $value = $lastname->appendChild($value);     
    
            $username = $xml->createElement('username'); 
            $username = $info->appendChild($username); 
            $value = $xml->createTextNode($row['user_username']); 
            $value = $username->appendChild($value); 
    
            $password = $xml->createElement('password'); 
            $password = $info->appendChild($password); 
            $value = $xml->createTextNode($row['user_password']); 
            $value = $password->appendChild($value); 
    
            $email = $xml->createElement('email'); 
            $email = $info->appendChild($email); 
            $value = $xml->createTextNode($row['user_email']); 
            $value = $email->appendChild($value); 
    		
    		
        } 
             
    $output = $xml->saveXML();
    
    echo "$output";
    
    ?>

  2. #12
    Allora, il file php va bene così com'è.
    Devi solo cambiare la funzione JS mostraInfo come segue
    codice:
    function mostraInfo(data)
    {
    var requestObj = readyAJAX(); 
    var url = "mostra_utenti_prova.php"; 
    var params = "q=" + data;
    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) { 
       var serverResponse = requestObj.responseXML;
       var header = serverResponse.getElementsByTagName("user");
    
       htmlString = "<table><tr><th>Nome</th><th>Cognome</th><th>Username</th><th>Password</th><th>Email</th></tr>";
    		
       for (i=0; i<header.length; i++)
       {
          htmlString += "<tr>";
          if (window.ActiveXObject)
          {
             htmlString += "<td>" + header[i].childNodes[0].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[3].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[4].text + "</td>";
          }
          else
          {
             htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[3].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[4].textContent + "</td>";
          }
          htmlString += "</tr>";
       }
       htmlString += "</table>";
    
       document.getElementById('info').innerHTML = htmlString;    
    
            } else { 
                alert(requestObj.statusText); 
            } 
        } 
    } 
    }
    ed eliminare il codice che hai messo nel div "info".

    Saluti.

  3. #13
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Ho provato il codice,ma mi compare la scritta nome, cognome... ma sotto non compare nulla come se non prendesse nulla dal database... ti posto qui i file:

    provasito2.php

    codice:
    <!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 "Hai bisogno di un altro browser."; 
            } 
        } 
    } 
    } 
    
    function mostraInfo(data)
    {
    var requestObj = readyAJAX(); 
    var url = "mostra_utenti_prova.php"; 
    var params = "q=" + data;
    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) { 
       var serverResponse = requestObj.responseXML;
       var header = serverResponse.getElementsByTagName("user");
    
       htmlString = "<table><tr><th>Nome</th><th>Cognome</th><th>Username</th><th>Password</th><th>Email</th></tr>";
    		
       for (i=0; i<header.length; i++)
       {
          htmlString += "<tr>";
          if (window.ActiveXObject)
          {
             htmlString += "<td>" + header[i].childNodes[0].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[3].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[4].text + "</td>";
          }
          else
          {
             htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[3].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[4].textContent + "</td>";
          }
          htmlString += "</tr>";
       }
       htmlString += "</table>";
    
       document.getElementById('info').innerHTML = htmlString;    
    
            } else { 
                alert(requestObj.statusText); 
            } 
        } 
    } 
    }
    </script> 
    <form>
    <form> 
    Seleziona Utente: 
    <select name="users" onChange="mostraInfo(this.value)"> 
    <?php 
    
    $db_host = "localhost"; 
    $db_user = "administrator"; 
    $db_password = "administrator"; 
    $db_database = "prova"; 
    
    //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>

    mostra_utenti_prova.php

    codice:
    <?php 
    header('Content-Type: text/xml');
    
    $db_host = "localhost"; 
    $db_user = "administrator"; 
    $db_password = "administrator"; 
    $db_database = "prova"; 
    
    $con = mysql_connect($db_host,$db_user,$db_password); 
    mysql_select_db($db_database, $con); 
    
    
    $q=$_POST['q']; 
    
    
    $sql="SELECT * 
    FROM user 
    WHERE user_id = '".$q."'"; 
    
    $result = mysql_query($sql); 
    
    $xml = new DomDocument('1.0'); 
        $info = $xml->createElement('informations'); 
        $info = $xml->appendChild($info); 
    
        while ($row = mysql_fetch_array($result)) 
        { 
            $firstname = $xml->createElement('firstname'); 
            $firstname = $info->appendChild($firstname); 
            $value = $xml->createTextNode($row['user_firstname']); 
            $value = $firstname->appendChild($value); 
                 
            $lastname = $xml->createElement('lastname'); 
            $lastname = $info->appendChild($lastname); 
            $value = $xml->createTextNode($row['user_lastname']); 
            $value = $lastname->appendChild($value);     
    
            $username = $xml->createElement('username'); 
            $username = $info->appendChild($username); 
            $value = $xml->createTextNode($row['user_username']); 
            $value = $username->appendChild($value); 
    
            $password = $xml->createElement('password'); 
            $password = $info->appendChild($password); 
            $value = $xml->createTextNode($row['user_password']); 
            $value = $password->appendChild($value); 
    
            $email = $xml->createElement('email'); 
            $email = $info->appendChild($email); 
            $value = $xml->createTextNode($row['user_email']); 
            $value = $email->appendChild($value); 
    		
    		
        } 
             
    $output = $xml->saveXML();
    
    
    ?>

  4. #14
    Facciamo una prova!
    Sostituisci $_POST con $_GET nel file mostra_utenti_prova.php
    e nella barra degl'indirizzi del browser richiama la pagina con

    http://nomesito/mostra_utenti_prova.php?q=XXX

    con XXX uguale ad un valore che esiste nel DB
    e posta qui l'output.

    EDIT:

    inserisci al fondo del file

    Codice PHP:
    $output $xml->saveXML();

    echo 
    $output//aggiungi questo 

  5. #15
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Mi fa corretto, ovvero

    Il file XML specificato apparentemente non ha un foglio di stile associato. L'albero del documento è mostrato di seguito.


    <informations>
    <firstname>"mette il mio nome"</firstname>
    <lastname>"mette qui il mio cognome</lastname>
    <username>"mette qui il mio username"</username>
    <password>"mette qui lapassword(Md5 perchè nel databse l'ho messa così"</password>
    <email>"qui mette la mia mail</email>
    </informations>

  6. #16
    ok, cambia il while come segue

    Codice PHP:
        while ($row mysql_fetch_array($result)) 
        {
            
    $user $xml-> createElement('user');
            
    $user $info->appendChild($user);
            
            
    $firstname $xml->createElement('firstname'); 
            
    $firstname $user->appendChild($firstname); 
            
    $value $xml->createTextNode($row['user_firstname']); 
            
    $value $firstname->appendChild($value); 
                 
            
    $lastname $xml->createElement('lastname'); 
            
    $lastname $user->appendChild($lastname); 
            
    $value $xml->createTextNode($row['user_lastname']); 
            
    $value $lastname->appendChild($value);     

            
    $username $xml->createElement('username'); 
            
    $username $user->appendChild($username); 
            
    $value $xml->createTextNode($row['user_username']); 
            
    $value $username->appendChild($value); 

            
    $password $xml->createElement('password'); 
            
    $password $user->appendChild($password); 
            
    $value $xml->createTextNode($row['user_password']); 
            
    $value $password->appendChild($value); 

            
    $email $xml->createElement('email'); 
            
    $email $user->appendChild($email); 
            
    $value $xml->createTextNode($row['user_email']); 
            
    $value $email->appendChild($value);     
        } 

  7. #17
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Continua a non funzionare

    Codice PHP:

    <?php 
    header
    ('Content-Type: text/xml');

    $db_host "localhost"
    $db_user "administrator"
    $db_password "administrator"
    $db_database "ticket"

    $con mysql_connect($db_host,$db_user,$db_password); 
    mysql_select_db($db_database$con); 


    $q=$_GET['q']; 





    $sql="SELECT * 
    FROM user 
    WHERE user_id = '"
    .$q."'"

    $result mysql_query($sql); 

    $xml = new DomDocument('1.0'); 
        
    $info $xml->createElement('informations'); 
        
    $info $xml->appendChild($info); 

       
    while (
    $row mysql_fetch_array($result))
        {
            
    $user $xml-> createElement('user');
            
    $user $info->appendChild($user);
            
            
    $firstname $xml->createElement('firstname');
            
    $firstname $user->appendChild($firstname);
            
    $value $xml->createTextNode($row['user_firstname']);
            
    $value $firstname->appendChild($value);
                 
            
    $lastname $xml->createElement('lastname');
            
    $lastname $user->appendChild($lastname);
            
    $value $xml->createTextNode($row['user_lastname']);
            
    $value $lastname->appendChild($value);     

            
    $username $xml->createElement('username');
            
    $username $user->appendChild($username);
            
    $value $xml->createTextNode($row['user_username']);
            
    $value $username->appendChild($value);

            
    $password $xml->createElement('password');
            
    $password $user->appendChild($password);
            
    $value $xml->createTextNode($row['user_password']);
            
    $value $password->appendChild($value);

            
    $email $xml->createElement('email');
            
    $email $user->appendChild($email);
            
    $value $xml->createTextNode($row['user_email']);
            
    $value $email->appendChild($value);     
        }
             
    $output $xml->saveXML();

    echo 
    $output;

    ?>

  8. #18
    Rimetti $_POST :P
    L'abbiamo cambiato solo per poter inserire i parametri dalla barra degl'indirizzi

  9. #19
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    PERFETTO! FUNZIONA!!! Grazie mille!!!


    Ora devo inviare dei dati presi tramite form al server (esempio numeri di carta di cretido)in maniera criptata xml, il server deve controllare i dati(se il numero di carta esiste nel database) e restituire transazione avvenuta oppure meno.

    Io ho fatto il classico form in php, come faccio a mandare criptato in xml?

    basta che tolga la select dal file provasito2 metta i form e poi dove inserisco il blocco di codice?

    Codice PHP:
    <?php


    require_once('header.php');
    require_once(
    'pagetop.inc');


    if (
    $_SESSION['log'] != 1)
    {
    echo 
    "Devi fare il login per entrare in questa sezione!" .
          
    "ritorna alla Home Page ed effettua il Login.

    "
    ;
    echo 
    "<a href=\"index.php\"><<< Clicca qui per ritornare alla Home Page</a></p>";
    exit();
    }
    ?>
    <html>
    <head>
    <title>Pagamento</title>

    <SCRIPT LANGUAGE="JavaScript">
    function ver()
       {
       for (i=0; i<4; ++i)
          if(document.forms[0].elements[i].value == "")
             {
             alert("Riempire tutti i campi obbligatori!");
             document.forms[0].elements[i].focus();
             return false;
             }
       return true;
       }
    </SCRIPT>

    </head>
    <body>




    <p align='center'>

    <h3> <p align='center'> Pagamento:</h3>
        
    </br>

      </p>


    <form name="modulo" action="autenticazione.php" method="post" onSubmit="return (ver());">

        <table align='center' width='100%' border='0'>

        <tr>

          <td width='18%'>Numero:</td>

          <td width="82%" bgcolor="#FFFFFF">

            <input name="numero" type="text" size="20" maxlength="25">
            
          
          

          <td width="0%"></td>

        </tr>
        
        <tr>

          <td width='18%'>Intestatario:</td>

          <td>

            <input name="intestatario" type="text" size="20" maxlength="50">
            


        </tr>  

        <tr>
         <tr>

          <td width='18%'>Scadenza:</td>

          <td>

            <input name="scadenzamese" type="text" size="02" maxlength="2">
            <input name="scadenzaanno" type="text" size="02" maxlength="2">
            
        

        </tr>

      
        <tr>

          <td width='18%'>Codice sicurezza:</td>

          <td>

            <input name="codicesicurezza" type="text" size="20" maxlength="40">
            
        

        </tr>
       
       
       <tr>
            <td colspan="2" align="center"><input type="submit" name="Submit" value="Invia il pagamento">
        </tr>
    </p>

    </table>

    </form>
      


    </body>
    </html>
    Grazie

  10. #20
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Devo lasciare intatto (eccetto cambiare ovviamente nome ai nodi figli ecc...) il file provasito2 e modificare il file del post precedente? Perchè mentre nell'esempio di prima (quello con la select) interrogo il databse e poi stampo... qui invece devo interrogare il database su ciò che metto io nei form e poi non stampare proprio nulla se non un messaggio ok oppure no...
    Come posso fare? Grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.