Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Problema con uno script php

    Sto creando un sito in php e più precisamente la parte della gestione news. per visualizzare le news dal mysql va bene, ma quando chiedo i form per creare una news non mi fa vedere niente

    ecco il file

    Codice PHP:
    <?
    //Queste due righe di codice permettono di non accedere direttamente alla pagina.
    if (eregi("modules/news/",$_SERVER['PHP_SELF']))
       {
    Header("Location: ../../index.php"); exit();}
    include(
    "includes/config.php");
    if (!isset(
    $_GET['azione'])) {

    /*SE L'AZIONE è "INDEX"....*/
    ?>
     [url="index.php?azione=nuova"]Crea nuova news[/url] 
    <?
    {
      
    $query "SELECT id,data,titolo FROM ".$table_prefix."_news ORDER BY data DESC LIMIT 0,10";
      
    $risultato mysql_query($query);
      while (
    $riga mysql_fetch_array($risultatoMYSQL_NUM))
      { echo 
    "<a href=\"index.php?azione=view&id=".$riga['id']."\">" $riga['data'] . $riga['titolo']."</a>
    "
    ; }

    }
    ##########                                    ###########
    /*         CONTROLLA SE E' SETTATA L'AZIONE        */
    if (isset($_GET['azione'])) {
      
    /* SE L'AZIONE E' "NUOVA".... */
      
    if ($_GET['azione']=="nuova")
    ?>
      <center>
    <form method=post action=index.php?azione=insert>
    Titolo:

    <input type=text size=40 name=titolo>



    Autore:

    <input type=text size=40 name=autore>



    E-mail:

    <input type=text size=40 name=mail>



    Sito web:

    <input type=text size=40 name=sitoweb>



    Testo:

    <textarea cols=40 rows=10 name=testo></textarea>



    Password:

    <input type=password size=40 name=pass>



     <input type=submit value=Invia> </form>   </center>
    <?
    /*SE L'AZIONE è "INDEX"....*/
    ?>
     [url="index.php?azione=nuova"]Crea nuova news[/url] 
    <?
    if ($_GET['azione']=="index")
    {
      
    $query "SELECT id,data,titolo FROM n43news ORDER BY data DESC LIMIT 0,10";
      
    $risultato mysql_query($query);
      while (
    $riga mysql_fetch_array($risultato))
      { echo 
    "<a href=\"index.php?azione=view&id=".$riga['id']."\">" $riga['data'] . 
     " 
    $riga['introduzione'] . " ".$riga['titolo']."</a>
    "
    ; }
    // SE L'AZIONE E' "INSERT".....
    }
    if (
    $_GET['azione']=="insert")
    {
      
    // SE LA PASSWORD E' SCORRETTA....
    if ($_POST['pass'] != $admin_pass)
    echo(
    "Password scorretta!! Se sei l'amministratore ritenta, altrimenti lascia stare.");
    // SE LA PASSWORD E' CORRETTA  . . .
    else
    {
      if (
    trim($_POST['titolo']) == "" OR trim($_POST['testo']) == "") { echo ("Non hai inserito niente nei campi titolo, testo o introduzione. Sono campi obbligatori!"); }
      else {
      
    $titolo $_POST['titolo'];
      
    $autore $_POST['autore'];
      
    $mail $_POST['mail'];
      
    $testo $_POST['testo'];
      
    $sitoweb $_POST['sitoweb'];

      
    $titolo addslashes(stripslashes($titolo));
      
    $autore addslashes(stripslashes($autore));
      
    $mail addslashes(stripslashes($mail));
      
    $testo addslashes(stripslashes($testo));
      
    $sitoweb addslashes(stripslashes($sitoweb));

      
    $titolo str_replace("<""&lt;"$titolo);
      
    $titolo str_replace(">""&gt;"$titolo);
      
    $autore str_replace("<""&lt;"$autore);
      
    $autore str_replace(">""&gt;"$autore);
      
    $testo str_replace("<""&lt;"$testo);
      
    $testo str_replace(">""&gt;"$testo);
      
    $testo nl2br($testo);

      
    $data date("Y-m-d");

      
    $query "INSERT INTO n43news (titolo, testo, data, autore, mail, sitoweb) VALUES ('$titolo', '$testo', '$data', '$autore', '$mail', '$sitoweb')";
      if (
    mysql_query($query))
      echo 
    "News inserita!";
      else
      echo (
    "News non inserita, errore numero ".mysql_errno() . ": " mysql_error());
      
    //endif;
      
    }
    }
    /* ####### FINE AZIONE "INSERT" ####### */
    }
    /* ######## SE L'AZIONE E' "VIEW".... ########### */
    if ($_GET['azione']=="view")
    {
      
    $query "SELECT titolo,testo,data,autore,mail,sitoweb FROM n43news WHERE id=".$_GET['id'];
      
    $risultato mysql_query($query);
      
    $riga mysql_fetch_array($risultato);

      
    $data $riga["data"];
      echo 
    "[b]".$riga["titolo"]."[/b]

    "
    ;
      echo 
    $riga["testo"]."

    "
    ;
      if (
    $riga["mail"] != "") echo $data.", <a href=mailto:".$riga["mail"].">".$riga["autore"]."</a>
    "
    ; else echo $data.","$riga["autore"]."
    "
    ; if ($riga["sitoweb"] != "") echo "<a href=\"".$riga["sitoweb"]."\">Sito Web</a>";
      
    ?>
    <? 
    echo "
    <a href=index.php?index>Torna alla pagina iniziale</a>
    "
    ;
    echo 
    "<a href=index.php?all>Visualizza tutti gli articoli</a>
    "
    ;
    /* ########## FINE AZIONE "VIEW" ########### */
    }
    /* ######## SE L'AZIONE E' "ALL".... ########### */
    if ($_GET['azione']=="all")
    {
      if (!isset(
    $start) OR $start<0)
      
    $start=0;
      
    $step 20;
      
    $query "SELECT id,data,titolo FROM n43news ORDER BY data DESC LIMIT ".$start.",".$step;
      
    $risultato mysql_query($query);
      while (
    $riga mysql_fetch_array($risultato))
      { echo 
    "<a href=\"index.php?azione=view&id=".$riga["id"]."\">" $riga["data"] . " - ".$riga["titolo"]."</a>
    "
    ; }
      
    ?>
      


      <table width=90% border=0><tr>
      <td width=20% align=left>
      <?
      
    if (isset($_GET['start']) && $_GET['start']>0)
      { 
    $start_back $_GET['start'] - $step;
      echo 
    "<a href=all.php?start=".$start_back.">precedenti</a>";
      }
      
    ?>
      </td>
      <?
      $query 
    "SELECT count(*) AS tot FROM n43news";
      
    $result mysql_query($query);
      
    $riga mysql_fetch_array($risultato);
      
    $pages intval(($riga["tot"]-1) / $step)+1;
      
    ?>
      <td width=60% align=center>
      <?
      
    for ($i=0$i<$pages AND $i<20$i++)
      { 
    $start_page $i $step;
      echo 
    "<a href=index.php?azione=all&start=".$start_page.">" . ($i+1) . "</a> ";
      }
      
    ?>
      </td>
      <td width=20%>
      <?
      
    if (isset($_GET['start']) && $_GET['start'] + $step $riga["tot"])
      { 
    $start_next $_GET['start'] + $step;
      echo 
    "<a href=index.php?azione=all&start=".$start_next.">successivi</a>";
      }
      
    ?>
      </td>
      </tr></table>
      

      <?
      
    echo "Cerca (separa le chiavi da una virgola)


           <form method=post action=index.php?azione=cerca>
           <input type=text name=chiave><input type=submit value=Cerca!>

           </form>"
    ;
    /* ########## FINE AZIONE "all" ########### */
    }
    /* ######## SE L'AZIONE E' "CERCA".... ########### */
    if ($_GET['azione']=="cerca")
    {
      
    $keys explode (","$_POST['chiave']);
      
    $query "";
      
    reset ($keys);
      while (list(,
    $parola) = each ($keys))
      { 
    $parola trim($parola);
      if (
    $parola != "")
      
    $query .= "titolo LIKE '%".$parola."%' OR testo LIKE '%".$parola."%' OR autore LIKE '%".$parola."%' OR ";
      }
      
    $query .= "0";
      
    $query "SELECT id, titolo, data FROM n43news WHERE " $query;
      
    $risultato mysql_query($query);
      while (
    $riga mysql_fetch_array($risultato))
      { echo 
    "<a href=\"index.php?azione=view&id=".$riga["id"]."\">" $riga["data"] . " - ".$riga["titolo"]."</a>
    "
    ; }
    /* ########## FINE AZIONE "CERCA" ########### */
    }
    /* ######## FINE DELLE AZIONI ########### */
    }
    }
    ?>
    vi prego aiutate questo povero principiante

    grazie mille in anticipo

  2. #2
    prova a mettere le graffe { } agli if
    magari è quello

  3. #3
    prova a mettere le graffe { } agli if
    niente....

  4. #4
    Richiedi il result set con indice numerico:

    codice:
    while ($riga = mysql_fetch_array($risultato, MYSQL_NUM))
    e poi richiami i valori con l'indice associativo

    codice:
    $riga['id']."\">" . $riga['data'] .
    usa mysql_fetch_assoc()

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

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 © 2025 vBulletin Solutions, Inc. All rights reserved.