• User Attivo

    creare download di un echo

    vorrei far eseguire il download all'utente di alcuni dati che ho in echo, cioè vorrei se possibile, inserirli in un foglio excel e scaricare il tutto.
    dunque, ho trovato uno script del genere, l'ho provato ma mi da diversi problemi e poi non mi crea nessun file xls

    <?php
    session_start();
    ?>

    <?php

    $id_user = $_SESSION['id_user'];
    $user = $_SESSION['user'];
    $gender = $_SESSION['gender'];
    $year=$_SESSION['year'];
    $month=$_SESSION['month'];
    $day=$_SESSION['day'];
    $country = $_SESSION['country'];
    $test_arousal_photo1 = $_SESSION['test_arousal_photo1'];
    $test_valence_photo1 = $_SESSION['test_valence_photo1'];
    $test_arousal_photo2 = $_SESSION['test_arousal_photo2'];
    $test_valence_photo2 = $_SESSION['test_valence_photo2'];
    $test_arousal_photo3 = $_SESSION['test_arousal_photo3'];
    $test_valence_photo3 = $_SESSION['test_valence_photo3'];
    $test_arousal_photo4 = $_SESSION['test_arousal_photo4'];
    $test_valence_photo4 = $_SESSION['test_valence_photo4'];
    $test_arousal_photo5 = $_SESSION['test_arousal_photo5'];
    $test_valence_photo5 = $_SESSION['test_valence_photo5'];
    $test_arousal_photo6 = $_SESSION['test_arousal_photo6'];
    $test_valence_photo6 = $_SESSION['test_valence_photo6'];
    $test_arousal_photo7 = $_SESSION['test_arousal_photo7'];
    $test_valence_photo7 = $_SESSION['test_valence_photo7'];
    $test_arousal_photo8 = $_SESSION['test_arousal_photo8'];
    $test_valence_photo8 = $_SESSION['test_valence_photo8'];
    $test_arousal_photo9 = $_SESSION['test_arousal_photo9'];
    $test_valence_photo9 = $_SESSION['test_valence_photo9'];
    $test_arousal_photo10 = $_SESSION['test_arousal_photo10'];
    $test_valence_photo10 = $_SESSION['test_valence_photo10'];

    if($test_arousal_photo1==null){$test_arousal_photo1="NULL";}
    if($test_valence_photo1==null){$test_valence_photo1="NULL";}
    if($test_arousal_photo2==null){$test_arousal_photo2="NULL";}
    if($test_valence_photo2==null){$test_valence_photo2="NULL";}
    if($test_arousal_photo3==null){$test_arousal_photo3="NULL";}
    if($test_valence_photo3==null){$test_valence_photo3="NULL";}
    if($test_arousal_photo4==null){$test_arousal_photo4="NULL";}
    if($test_valence_photo4==null){$test_valence_photo4="NULL";}
    if($test_arousal_photo5==null){$test_arousal_photo5="NULL";}
    if($test_valence_photo5==null){$test_valence_photo5="NULL";}
    if($test_arousal_photo6==null){$test_arousal_photo6="NULL";}
    if($test_valence_photo6==null){$test_valence_photo6="NULL";}
    if($test_arousal_photo7==null){$test_arousal_photo7="NULL";}
    if($test_valence_photo7==null){$test_valence_photo7="NULL";}
    if($test_arousal_photo8==null){$test_arousal_photo8="NULL";}
    if($test_valence_photo8==null){$test_valence_photo8="NULL";}
    if($test_arousal_photo9==null){$test_arousal_photo9="NULL";}
    if($test_valence_photo9==null){$test_valence_photo9="NULL";}
    if($test_arousal_photo10==null){$test_arousal_photo10="NULL";}
    if($test_valence_photo10==null){$test_valence_photo10="NULL";}

    $connessione=mysql_connect("localhost", "");
    $selezione_db=mysql_select_db("guest_book", $connessione);

    echo "welcome ";
    echo" <BR><BR><BR><BR> your values:<BR>
    <BR>test arousal photo1= ". $test_arousal_photo1 ."<br>test valence photo1= " .$test_valence_photo1 .
    "<br>test arousal photo2= " . $test_arousal_photo2 . "<br>test valence photo2= " . $test_valence_photo2 .
    "<br>test arousal photo3= " . $test_arousal_photo3 . "<br>test valence photo3= " . $test_valence_photo3 .
    "<br>test arousal photo4= " . $test_arousal_photo4 . "<br>test valence photo4= " . $test_valence_photo4 .
    "<br>test arousal photo5= " . $test_arousal_photo5 . "<br>test valence photo5= " . $test_valence_photo5 .
    "<br>test arousal photo6= " . $test_arousal_photo6 . "<br>test valence photo6= " . $test_valence_photo6 .
    "<br>test arousal photo7= " . $test_arousal_photo7 . "<br>test valence photo7= " . $test_valence_photo7 .
    "<br>test arousal photo8= " . $test_arousal_photo8 . "<br>test valence photo8= " . $test_valence_photo8 .
    "<br>test arousal photo9= " . $test_arousal_photo9 . "<br>test valence photo9= " . $test_valence_photo9 .
    "<br>test arousal photo10= " . $test_arousal_photo10 . "<br>test valence photo10= " . $_SESSION['test_valence_photo10'];

    $query="INSERT INTO messaggi (id_user,user,gender,date_of_birth,country,test_arousal_photo1,test_valence_photo1,test_arousal_photo2,test_valence_photo2,test_arousal_photo3,test_valence_photo3,test_arousal_photo4,test_valence_photo4,test_arousal_photo5,test_valence_photo5,test_arousal_photo6,test_valence_photo6,test_arousal_photo7,test_valence_photo7,test_arousal_photo8,test_valence_photo8,test_arousal_photo9,test_valence_photo9,test_arousal_photo10,test_valence_photo10,date)";
    $query.=" VALUES ('$id_user','$user','$gender','$year-$month-$day','$country',$test_arousal_photo1,$test_valence_photo1,$test_arousal_photo2,$test_valence_photo2,$test_arousal_photo3,$test_valence_photo3,$test_arousal_photo4,$test_valence_photo4,$test_arousal_photo5,$test_valence_photo5,$test_arousal_photo6,$test_valence_photo6,$test_arousal_photo7,$test_valence_photo7,$test_arousal_photo8,$test_valence_photo8,$test_arousal_photo9,$test_valence_photo9,$test_arousal_photo10,$test_valence_photo10, now())" ;

    $inserimento=mysql_query($query);
    mysql_close($connessione);

    ?>

    <html>
    <head>
    <p><BR>
    <BR>
    </p>
    <p><BR>
    <BR>
    <img src="image value.JPG" alt="image value" width="600 height=" height="748"800" /> <img src="valence-arousal.JPG" alt="valence arousal" width="551" height="540" /></p>
    <p><p align="right">
    <title></title>
    </head>

    <?php
    $DB_Server = "localhost"; //your MySQL Server
    $DB_Username = ""; //your MySQL User Name
    $DB_Password = ""; //your MySQL Password
    $DB_DBName = "guest_book"; //your MySQL Database Name
    $DB_TBLName = "messaggi"; //your MySQL Table Name

    $sql = "Select * from $DB_TBLName";

    //create MySQL connection
    $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
    or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
    //select database
    $Db = @mysql_select_db($DB_DBName, $Connect)
    or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
    //execute query
    $result = @mysql_query($sql,$Connect)
    or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());

    $file_type = "vnd.ms-excel";
    $file_ending = "xls";

    //header info for browser: determines file type ('.doc' or '.xls')
    header("Content-Type: application/$file_type");
    header("Content-Disposition: attachment; filename=prova1.$file_ending");
    header("Pragma: no-cache");
    header("Expires: 0");

    /* Start of Formatting for Word or Excel */

    //define separator (defines columns in excel & tabs in word)
    $sep = "\t"; //tabbed character

    //start of printing column names as names of MySQL fields
    for ($i = 0; $i < mysql_num_fields($result); $i++)
    {
    echo mysql_field_name($result,$i) . "\t";
    }
    print("\n");
    //end of printing column names

    //start while loop to get data
    while($row = mysql_fetch_row($result))
    {
    //set_time_limit(60); // HaRa
    $schema_insert = "";
    for($j=0; $j<mysql_num_fields($result);$j++)
    {
    if(!isset($row[$j]))
    $schema_insert .= "NULL".$sep;
    elseif ($row[$j] != "")
    $schema_insert .= "$row[$j]".$sep;
    else
    $schema_insert .= "".$sep;
    }
    $schema_insert = str_replace($sep."$", "", $schema_insert);
    $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
    $schema_insert .= "\t";
    print(trim($schema_insert));
    print "\n";
    }

    ?>


  • User Newbie

    Prova a togliere tutta l'intestazione html, e cioè :

    <html>
    <head>
    <p><BR>
    <BR>
    </p>
    <p><BR>
    <BR>
    <img src="image value.JPG" alt="image value" width="600 height=" height="748"800" /> <img src="valence-arousal.JPG" alt="valence arousal" width="551" height="540" /></p>
    <p><p align="right">
    <title></title>
    </head>

    vedrai che così facendo se il resto dello script è corretto quando verrà richiesto non aprirà una nuova pagina, ma la quasiica finestrina per i download.


  • User Attivo

    no, purtroppo mi invalida le variabili e quindi scrive cosi':

    Notice: Undefined index: id_user in c:\programmi\easyphp1-8\www\salvastep2.php on line 11

    Notice: Undefined index: user in c:\programmi\easyphp1-8\www\salvastep2.php on line 12

    Notice: Undefined index: gender in c:\programmi\easyphp1-8\www\salvastep2.php on line 13

    Notice: Undefined index: year in c:\programmi\easyphp1-8\www\salvastep2.php on line 14

    Notice: Undefined index: month in c:\programmi\easyphp1-8\www\salvastep2.php on line 15

    Notice: Undefined index: day in c:\programmi\easyphp1-8\www\salvastep2.php on line 16

    Notice: Undefined index: country in c:\programmi\easyphp1-8\www\salvastep2.php on line 17

    Notice: Undefined index: test_arousal_photo1 in c:\programmi\easyphp1-8\www\salvastep2.php on line 18

    Notice: Undefined index: test_valence_photo1 in c:\programmi\easyphp1-8\www\salvastep2.php on line 19

    Notice: Undefined index: test_arousal_photo2 in c:\programmi\easyphp1-8\www\salvastep2.php on line 20

    Notice: Undefined index: test_valence_photo2 in c:\programmi\easyphp1-8\www\salvastep2.php on line 21

    Notice: Undefined index: test_arousal_photo3 in c:\programmi\easyphp1-8\www\salvastep2.php on line 22

    Notice: Undefined index: test_valence_photo3 in c:\programmi\easyphp1-8\www\salvastep2.php on line 23

    Notice: Undefined index: test_arousal_photo4 in c:\programmi\easyphp1-8\www\salvastep2.php on line 24

    Notice: Undefined index: test_valence_photo4 in c:\programmi\easyphp1-8\www\salvastep2.php on line 25

    Notice: Undefined index: test_arousal_photo5 in c:\programmi\easyphp1-8\www\salvastep2.php on line 26

    Notice: Undefined index: test_valence_photo5 in c:\programmi\easyphp1-8\www\salvastep2.php on line 27

    Notice: Undefined index: test_arousal_photo6 in c:\programmi\easyphp1-8\www\salvastep2.php on line 28

    Notice: Undefined index: test_valence_photo6 in c:\programmi\easyphp1-8\www\salvastep2.php on line 29

    Notice: Undefined index: test_arousal_photo7 in c:\programmi\easyphp1-8\www\salvastep2.php on line 30

    Notice: Undefined index: test_valence_photo7 in c:\programmi\easyphp1-8\www\salvastep2.php on line 31

    Notice: Undefined index: test_arousal_photo8 in c:\programmi\easyphp1-8\www\salvastep2.php on line 32

    Notice: Undefined index: test_valence_photo8 in c:\programmi\easyphp1-8\www\salvastep2.php on line 33

    Notice: Undefined index: test_arousal_photo9 in c:\programmi\easyphp1-8\www\salvastep2.php on line 34

    Notice: Undefined index: test_valence_photo9 in c:\programmi\easyphp1-8\www\salvastep2.php on line 35

    Notice: Undefined index: test_arousal_photo10 in c:\programmi\easyphp1-8\www\salvastep2.php on line 36

    Notice: Undefined index: test_valence_photo10 in c:\programmi\easyphp1-8\www\salvastep2.php on line 37
    welcome
    Notice: Undefined index: test_valence_photo10 in c:\programmi\easyphp1-8\www\salvastep2.php on line 85

    your values:

    test arousal photo1= NULL
    test valence photo1= NULL
    test arousal photo2= NULL
    test valence photo2= NULL
    test arousal photo3= NULL
    test valence photo3= NULL
    test arousal photo4= NULL
    test valence photo4= NULL
    test arousal photo5= NULL
    test valence photo5= NULL
    test arousal photo6= NULL
    test valence photo6= NULL
    test arousal photo7= NULL
    test valence photo7= NULL
    test arousal photo8= NULL
    test valence photo8= NULL
    test arousal photo9= NULL
    test valence photo9= NULL
    test arousal photo10= NULL
    test valence photo10= Couldn't connect to MySQL:
    Accesso non consentito per l'utente: 'ODBC'@'localhost' (Password: NO)
    1045


  • User Attivo

    il problema è questo adesso:
    Warning: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1-8\www\salvastep2.php:8) in c:\programmi\easyphp1-8\www\salvastep2.php on line 137

    Warning: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1-8\www\salvastep2.php:8) in c:\programmi\easyphp1-8\www\salvastep2.php on line 138

    Warning: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1-8\www\salvastep2.php:8) in c:\programmi\easyphp1-8\www\salvastep2.php on line 139

    Warning: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1-8\www\salvastep2.php:8) in c:\programmi\easyphp1-8\www\salvastep2.php on line 140

    cosa sbaglio?


  • User Attivo

    sbagli a mettere l'html prima di

    
    //header info for browser: determines file type ('.doc' or '.xls') 
    header("Content-Type: application/$file_type"); 
    header("Content-Disposition: attachment; filename=prova1.$file_ending"); 
    header("Pragma: no-cache"); 
    header("Expires: 0");