Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
BuzzPoll (Sondaggio PHP) - CreaNuovoSondaggio.php

CreaNuovoSondaggio.php

Caricato da: A_butta
Scarica il programma completo

  1. <?
  2. include ('config.php');
  3.  
  4. function SpaceEraser($text)
  5. {
  6.     for ($i=0;$i<=strlen($text);$i++)
  7.       if (ord($text[$i]) != 32)
  8.         $newStr .= $text[$i];
  9.     return $newStr;
  10. }
  11.  
  12. function pulisciRighe($array)
  13. {
  14.     $newArray = array();
  15.     $k = 0;
  16.     foreach ($array as $val)
  17.     {
  18.         if (ord(spaceEraser($val))!=13)
  19.           $newArray[] = $val;
  20.     }
  21.     return $newArray;
  22. }
  23.  
  24. function creaSondaggio($titolo,$testo)
  25. {
  26.   include_once('connetti.php');
  27.   $data = time() + 7200;
  28.   $nRighe = count($testo);
  29.   for ($i=0;$i<$nRighe;$i++)
  30.     $voti[] = '0';
  31.   $voti=implode('~',$voti);
  32.   $insert = mysql_query("insert into sondaggi (titolo,voci,dataCreazione,votazione) VALUES('$titolo','".implode("\r\n",$testo)."','$data','$voti')");
  33.   return $insert;  
  34. }
  35.  
  36. if (isset($_POST['submit']))
  37. {
  38.     $testo = $_POST['textarea'];
  39.     $testo = pulisciRighe(explode("\n",$testo));
  40.     if ((count($text) == 0 && $testo[0] == '') || ($_POST['title'] == ''))
  41.     {
  42.       if (count($text) == 0 && $testo[0] == '')
  43.           $errore = 'Inserire le voci del sondaggio';
  44.       if ($_POST['title'] == '')
  45.           $errore = 'Inserire un titolo al sondaggio';
  46.     }
  47.     else
  48.     {
  49.         if (creaSondaggio($_POST['title'],$testo))
  50.         {
  51.           header('location: lista.php');
  52.           die();
  53.         }
  54.         else
  55.           $errore = 'Errore nella creazione del sondaggio';          
  56.     }
  57. }
  58. ?>
  59. <html>
  60. <head>
  61. <title>Crea un tuo sondaggio</title>
  62. </head>
  63. <form action="" method="post">
  64. <div style="width: 510px; border:1px solid;">
  65. <label for="title">Titolo:</label><br />
  66. <input type="input" name="title" id="title" style="width: 503px" /></br><br />
  67. <label for="textarea">Inserire nel box sottostante le opzioni del sondaggio (1 per riga)</label><br />
  68. <textarea type="textarea" rows="20" cols="60" name="textarea" id="textarea"></textarea><br />
  69. <input style="margin: 0 150px auto;" type="submit" name="submit" value="Invia Sondaggio">
  70. <br />
  71. <span style="color:red"><? echo $errore ?></span>
  72. </div>
  73. </form>